我有这个
var options = new Array("A","B","C");
var selectHtml="";
$.each( options, function( index, value ) {
var option = value;
selectHtml += '<select id="p_'+index+'" >';
selectHtml +='<option value="p_yes_'+index+'">Yes ' + option + '</option>';
selectHtml +='<option value="p_no_'+index+'">No ' + option + '</option>';
selectHtml +='</select>';
});我想对每个选择创建一个警报(p_A,p_B,.)当用户更改该值时。
谢谢大家。
发布于 2014-04-23 08:27:41
你需要的js是这样的
$(document).on("change","[id^='p_']",function(){
alert('Alert message goes here');
});发布于 2014-04-23 08:22:37
将html追加到DOM中,然后使用.on()为动态生成的元素附加事件。使用attribute starts with selector将事件附加到只有id以p_开头的元素。试试这个:
$(document).on("change","select[id^='p_']",function(){
alert($(this).val());
});发布于 2014-04-23 08:27:20
把这个添加到脚本标签中-
$("select").change(function(){
alert("I am clicked");
});https://stackoverflow.com/questions/23238620
复制相似问题