Cod*_*ore 2 javascript jquery select onchange
我正在尝试选择1更新选择2然后选择2火.
选择2只在直接控制时发射..我很难过!
码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Select Firing</title>
</head>
<body>
<p>Select 1 updates Select 2, but select 2's alert does not fire</p>
<select id="select1">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<p>Select 2 only fires alert when controlled directly</p>
<div>
<select id="select2" onchange="alert(this.value)">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
</div>
</body>
<script src="js/jquery-1.6.4.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
$(function() { //run on document.ready
$("#select1").change(function() { //this occurs when select 1 changes
$("#select2").val($(this).val());
});
});
});
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
谢谢!
$("#select1").change(function() {
$("#select2").val($(this).val()).trigger('change');
//or
$("#select2").val($(this).val()).change();
});
Run Code Online (Sandbox Code Playgroud)
这是你需要的吗?还是我错过了什么?
| 归档时间: |
|
| 查看次数: |
1541 次 |
| 最近记录: |