Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jQuery从select中删除_Jquery_Html_Select - Fatal编程技术网

使用jQuery从select中删除

使用jQuery从select中删除,jquery,html,select,Jquery,Html,Select,我试图在上面做的是从选择中删除一个选项,其中选项值等于currentSelect。但是,这将返回错误 未捕获错误:语法错误,无法识别的表达式:selectMail 期权[价值]=dasd@dasd.se] 这里发生了什么?属性的值应该用引号括起来 应该是 var currentSelect = 'option1'; $('#selectMail option[value=' + currentSelect + ']').remove(); 试一试 你的意思是删除当前选中的选项吗?如果他得到引号

我试图在上面做的是从选择中删除一个选项,其中选项值等于currentSelect。但是,这将返回错误

未捕获错误:语法错误,无法识别的表达式:selectMail 期权[价值]=dasd@dasd.se]


这里发生了什么?

属性的值应该用引号括起来

应该是

var currentSelect = 'option1';
$('#selectMail option[value=' + currentSelect + ']').remove();
试一试


你的意思是删除当前选中的选项吗?如果他得到引号[],有什么区别?我在问,因为我不明白两者之间的区别,你能解释一下还是发一个链接?
$('#selectMail option[value="' + currentSelect + '"]').remove();
$('#selectMail option[value="' + currentSelect + '"]').remove();