<select class="select1">
<option value="1">1</option>
<option value="2"></option>
</select>
<select class="select2">
</select>
对于页面中已有的静态元素 select1中的option,对其绑定click事件一般主要可以通过以下方法:
第一种:
$(".select1 option").bind("click",function(){});
第二种:
$(".select1 option").click(function(){});
但是对于页面中动态添加的元素,如select2中的option(当前不存在),对其绑定click事件的方法一般为:
第一种:
$(".select2").delegate("option","click",function(){});//注意"option"一定要写在delegate函数里面
第二种:
$(".select2").on("click","option",function(){});//注意"option"一定要写在on函数里面
当然对于静态元素也可以采用针对动态元素的方法
$(".select1").delegate("option","click",function(){});
或:$(".select1 option").delegate("click",function(){});//这里"option"的位置不重要
$(".select1").on("click","option",function(){});
$(".select1 option").on("click",function(){});//这里"option"的位置一样不重要
这里注意一下delegate函数和on函数的参数位置即可。