use*_*568 7 html javascript jquery event-handling
当select选项中的任何选项被更改时,如何在jQuery中检测到?
例如[伪代码]:
event handler function -> option changed(){
//do some stuff
}
Run Code Online (Sandbox Code Playgroud)
编辑:
我有以下选择:
<select id = "selectattribute">
<OPTION VALUE="0">Choose Attribute</OPTION>
<?php echo($options);?>
</select>
Run Code Online (Sandbox Code Playgroud)
我在jQuery中尝试这个:
$(document).ready(function() {
$("#selectattribute").change(function() {
alert('Handler for .change() called.');
});
});
Run Code Online (Sandbox Code Playgroud)
什么都没发生......功能不是触发.
编辑:当我使用$("#select")
而不是$("#selectattribute")...can you not apply it to particular select tags?
<form>
<input class="target" type="text" value="Field 1" />
<select class="target">
<option value="option1" selected="selected">Option 1</option>
<option value="option2">Option 2</option>
</select>
</form>
<div id="other">
Trigger the handler
</div>
Run Code Online (Sandbox Code Playgroud)
事件处理程序可以绑定到文本输入和选择框:
$('.target').change(function() {
alert('Handler for .change() called.');
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13108 次 |
最近记录: |