Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在为我的应用程序做一些 javascript/jquery,我需要一些帮助。
我有很多选择。我想选择属性 name='myName' 的选项。
我知道按值设置它非常简单。
$("#my-select").val(myVal);
谢谢您的帮助。
你可以这样做:
$("#my-select option[name='myName']").prop('selected', true);
查看工作演示
$("option[name='myName']").prop('selected',true);
jsFiddle 示例
但是,如评论中所述,选项元素的 name 属性已过时。