Javascript 基于它更改选项值';jQuery中的当前值

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

我有以下HTML:

<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
)它是选项的文本,但除非您实际更改选项的内容,否则您永远不需要在中选择那么远。它是选项的文本,但是,除非您实际更改了选项的内容,否则您永远不需要在中选择那么远。