Javascript 更改选定值事件不适用于
当下拉列表的选定值更改时,以下代码不起作用。如果有任何错误,请更正Javascript 更改选定值事件不适用于,javascript,jquery,html,Javascript,Jquery,Html,当下拉列表的选定值更改时,以下代码不起作用。如果有任何错误,请更正 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <script src="jquery-1.9.1.js"></script> <script type="text/javascript"> $(doc
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="jquery-1.9.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
("#theSelect").change(function(){
alert("a");
});
});
</script>
</head>
<body>
<select id="theSelect">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</body>
</html>
你错过了选择前的$
$丢失,因此jQuery无法识别它
更改如下
$("#theSelect").change(function(){
alert("a");
});
用这个
$(document).ready(function() {
$("select").change(function(){
alert("a");
});
});
您缺少$/jQuery=>select.change函数{aw You fast:+1thanx…非常非常…感谢大家…愿上帝保佑大家…thanx…非常…感谢大家…愿上帝保佑大家
$(document).ready(function() {
$("select").change(function(){
alert("a");
});
});
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<select onchange=categories(this);>
<option value="option1">Option1</option>
<option value="option2">Option2</option>
<option value="option3">Option3</option>
<option value="option4">Option4</option>
<option value="option5">Option5</option>
</select>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
function categories(el) {
var category = el.options[el.selectedIndex].value;
alert(category);
}
</script>
</body>
</html>