[英]Jquery how to select option with value
我在代码中定义了一个变量,如下所示:
var select = $('.selMake');
我想选择值为“占位符”的选项。 如何使用变量选择选项? 我需要更改具有值“占位符”的选项的html
尝试
$("select.selMake").val("placeholder");
使用变量:
var $select = $('.selMake');
$select.val("placeholder");
通常,在指示jquery对象时,使用$前缀是一种好习惯。
根据评论进行编辑:尝试
$select.find('option[value="placeholder"]').text("newText");
“选择”和“选项”是什么意思? 是下拉列表选择HTML吗?
如果是这样,您可以尝试使用下面的代码来选择具有占位符值的选项:
var select = $('.selMake');
//select the option that have value of placeholder
var optionWithPlaceholder = select.find("option[value='placeholder']");
//you can do anyting here
optionWithPlaceholder.html("after edit");
我在这里尝试了该代码: http : //jsfiddle.net/Lg67qcj1/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.