选择更改jquery不工作 [英] select on change jquery not working

查看:78
本文介绍了选择更改jquery不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到下面的代码似乎不起作用:

< ',function(){if('.chosen-select'.value =='1'){$(#tips)。html(你想添加的颜色);} else if(' .chosen-select'.value =='2'){$(#tips)。html(您要添加的文本);}});

< script src =https://ajax.googleapis.com/ajax/libs/jquery/ 2.1.0 / jquery.min.js>< / script>< div id =tips>< / div>< select class =chosen-selectstyle =width:290px; NAME = 选项 > < option value =1>更改背景颜色< / option> < option value =2>插入文字< / option> < option value =3>插入箭头< / option>< / select>

我的网络浏览器控制台没有给我任何错误。该代码假设根据更改选择选项值来更改div的html。

解决方案

'。selected-select'.value 将不起作用,因为它既不是有效的jQuery表达式,也不是JavaScript。而是使用 $('。selected-select')。val() this.value $(this).val()



jsFiddle示例


I have the following code that does not seem to work:

$('.chosen-select').on('change', function() {
    if ('.chosen-select'.value == '1') {
        $("#tips").html("the color that you want to add.");
    } else if ('.chosen-select'.value == '2') {
        $("#tips").html("the text that you want to add.");
    }
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div id="tips"></div>
<select class="chosen-select" style="width:290px;" name="option">
    <option value="1">change background colour</option>
    <option value="2">insert text</option>
    <option value="3">insert arrow</option>
</select>

My web browser console is not giving me any error. The code is suppose to change the html of the div based on changing the select option value.

解决方案

This '.chosen-select'.value won't work as it's neither a valid jQuery expression nor JavaScript. Instead use $('.chosen-select').val(), this.value or $(this).val().

jsFiddle example

这篇关于选择更改jquery不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆