Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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选项文本选择器问题 彼得 掸_Jquery - Fatal编程技术网

jquery选项文本选择器问题 彼得 掸

jquery选项文本选择器问题 彼得 掸,jquery,Jquery,如何设置选项的text=peter selected? 像这样$('#name option[text=peter]')。attr('selected',true) 也 工作。可能重复[by jquery,设置为html选择元素选项,按文本选择,而不是值]()@BRAVO,我建议使用…attr('selected',true)而不是“selected”,而是“selected”,但这确实有效(或应该有效)。它应该是$(“#名称选项[text=peter]”);由于它是一个选择框,其他选项是$(“

如何设置选项的text=peter selected?
像这样
$('#name option[text=peter]')。attr('selected',true)


工作。

可能重复[by jquery,设置为html选择元素选项,按文本选择,而不是值]()@BRAVO,我建议使用
…attr('selected',true)
而不是
“selected”,而是“selected”
,但这确实有效(或应该有效)。它应该是$(“#名称选项[text=peter]”);由于它是一个选择框,其他选项是$(“#name option:contains('peter')”)。attr('selected','selected');事实上你是对的,但是(“选中”、“选中”)也起作用。
<select id="name">
 <option value="1005">peter</option>
 <option value="2056" selected="selected">shan</option>
</select>
 $("#name option[value='1005']").attr('selected','selected');
$("#name option[text=peter]").attr("checked", "checked");