Javascript 基于它更改选项值';jQuery中的当前值
我有以下HTML:Javascript 基于它更改选项值';jQuery中的当前值,javascript,jquery,Javascript,Jquery,我有以下HTML: <select class="file_image_type" name="file_image_type"> <option>Gallery</option> <option>Feature</option> <option>Thumbnail</option> </select> 我可以使用以下方法将图像设置为功能: c
<select class="file_image_type" name="file_image_type">
<option>Gallery</option>
<option>Feature</option>
<option>Thumbnail</option>
</select>
我可以使用以下方法将图像设置为功能:
current.find(".file_image_type").val("Feature");
“Gallery”不是
val()
,它是text()
“Gallery”不是val()
,它是text()
人,人,你不需要在jQuery中直接选择选项。我真不敢相信我有多少次看到这个错误
$('.file_image_type').change(function() {
$('.file_image_type').not(this).each(function() {
var $this = $(this);
if ($this.val() === 'Feature') {
$this.val('Gallery');
}
});
});
人员,人员,您不需要直接在jQuery中选择选项。我真不敢相信我有多少次看到这个错误
$('.file_image_type').change(function() {
$('.file_image_type').not(this).each(function() {
var $this = $(this);
if ($this.val() === 'Feature') {
$this.val('Gallery');
}
});
});
您的选项
元素没有值
属性,因此您不能通过它来选择它们javascript上下文中的“当前”属性是什么,元素必须具有该属性。您可以将Gallery
等标记更改为Gallery
您的选项
元素没有值
属性,因此您不能通过它来选择它们javascript上下文中的“当前”属性是什么,元素必须具有该属性。您可以将标记(如Gallery
更改为Gallery
)它是选项的文本,但除非您实际更改选项的内容,否则您永远不需要在中选择那么远。它是选项的文本,但是,除非您实际更改了选项的内容,否则您永远不需要在中选择那么远。