Javascript jQuery.remove()不';不要在IE8中开火
请问谁能解释一下 在我的函数中,我使用Javascript jQuery.remove()不';不要在IE8中开火,javascript,jquery,Javascript,Jquery,请问谁能解释一下 在我的函数中,我使用.remove()删除框中的一行(我的意思是删除),但为什么它不起作用 在FF中看起来不错,但在IE8中。。。失败 让我们看一个例子: <form name="test"> 我没有IE8要测试,但有几件事可能是你的问题: 1) jquery值选择器应该用引号括起来。改变 $(“#car2选项[value=“+car1_selected+”])。删除() 到 $(“#car2选项[值=”+car1_selected+“]”)。删除() 注意本例中
.remove()
删除
框中的一行(我的意思是删除
),但为什么它不起作用
在FF中看起来不错,但在IE8中。。。失败
让我们看一个例子:
<form name="test">
我没有IE8要测试,但有几件事可能是你的问题: 1) jquery值选择器应该用引号括起来。改变
$(“#car2选项[value=“+car1_selected+”])。删除()代码>
到
$(“#car2选项[值=”+car1_selected+“]”)。删除()代码>
注意本例中添加的单引号(也可以使用转义双引号)
2) 养成使用完整javascript选择器(或jquery等效选择器)的习惯:
car1\u selected=document.test.car1.value代码>
应该是
car1_selected = document.getElementById("car1").value;
事实上,这可能是您的问题,因为“test”实际上不是一个id,而是一个名称。您的代码是什么?你的手指在哪里?你能发一个链接到这个页面吗?@lovepong:你不再需要内联JavaScript了。。。您现在正在使用jQuery!删除此项:onchange=
并将其添加到jQuery函数中:$('#car1')。更改(函数(){//stuff_to_do/})代码>@sparky672:我试图使用你的解决方案,但仍然不起作用。@lovepong:那不是我解决你问题的方法。这是关于内联代码的一般建议。
function car_remove()
{
// car1_selected = document.test.car1.value; *Don't use this its a plain javascript*
// use this. Always try to use jQuery API's instead of conventional JS
car1_selected = $('#car1 option[selected]').val();
$("#car1 option[value="+ car1_selected +"]").remove();
}
function car_remove()
{
car1_selected = document.test.car1.value;
$("#car2 option[value="+ car1_selected +"]").remove();
}
car1_selected = document.getElementById("car1").value;
function car_remove()
{
// car1_selected = document.test.car1.value; *Don't use this its a plain javascript*
// use this. Always try to use jQuery API's instead of conventional JS
car1_selected = $('#car1 option[selected]').val();
$("#car1 option[value="+ car1_selected +"]").remove();
}