I've got a page that has a dropdown menu, and upon selection, creates a new element (a table) using an AJAX call. Firebug shows this on action:
我有一个带有下拉菜单的页面,在选择后,使用AJAX调用创建一个新元素(表)。 Firebug在行动中显示:
The actual code for this is:
实际代码是:
select name="category" id="category" onchange="load(this.value)
However, in addition to it creating a new table, I'd like it to destroy/ not display another table that's already on the page. The table has class="table2" id="PR". What additional code do I put into that select tag above? Thanks
但是,除了创建一个新表之外,我还希望它能够销毁/不显示已经在页面上的另一个表。该表具有class =“table2”id =“PR”。我在上面的select标签中添加了哪些附加代码?谢谢
3 个解决方案
#1
3
Try with the following:
尝试使用以下内容:
$('#PR').remove();
But maybe you'll need to make a function to call onchange:
但也许你需要创建一个函数来调用onchange:
function mychange(event)
{
load( event.currentTarget.value );
$('#PR').remove();
}
select name="category" id="category" onchange="mychange(event)"
#2
2
I would change it so you have this code instead:
我会改变它,所以你有这个代码:
$(function() {
$('#category').change(function() {
load($(this).val());
$('#PR').hide(); // or .remove() if you want to completely remove it;
});
});
You can then remove the onchange from the select tag as it is wired up via the jquery event.
然后,您可以在通过jquery事件连接时从select标记中删除onchange。
#3
0
Without jQuery try:
没有jQuery尝试:
onchange="load(this.value); document.getElementById('table1').style.display='none';"
#1
3
Try with the following:
尝试使用以下内容:
$('#PR').remove();
But maybe you'll need to make a function to call onchange:
但也许你需要创建一个函数来调用onchange:
function mychange(event)
{
load( event.currentTarget.value );
$('#PR').remove();
}
select name="category" id="category" onchange="mychange(event)"
#2
2
I would change it so you have this code instead:
我会改变它,所以你有这个代码:
$(function() {
$('#category').change(function() {
load($(this).val());
$('#PR').hide(); // or .remove() if you want to completely remove it;
});
});
You can then remove the onchange from the select tag as it is wired up via the jquery event.
然后,您可以在通过jquery事件连接时从select标记中删除onchange。
#3
0
Without jQuery try:
没有jQuery尝试:
onchange="load(this.value); document.getElementById('table1').style.display='none';"