syr*_*ull 1 html javascript jquery
我有以下代码似乎不起作用:
$('.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.");
}
});Run Code Online (Sandbox Code Playgroud)
<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>Run Code Online (Sandbox Code Playgroud)
我的网络浏览器控制台没有给我任何错误.代码假设基于更改选择选项值来更改div的html.
这'.chosen-select'.value不起作用,因为它既不是有效的jQuery表达式也不是JavaScript.而是使用$('.chosen-select').val(),this.value或$(this).val().