动态创建的Jquery selectmenu未被触发
我需要这个脚本的帮助。我正在动态创建一个jquery selectmenu 如果您在使用html创建的第一个selectmenu上进行选择,则会触发警报。如果您单击“Agregar Habitation”按钮创建一个selectmenu,然后在该selectmenu上进行任何选择,则不会触发警报 你知道我做错了什么吗 HTML动态创建的Jquery selectmenu未被触发,jquery,events,onclick,Jquery,Events,Onclick,我需要这个脚本的帮助。我正在动态创建一个jquery selectmenu 如果您在使用html创建的第一个selectmenu上进行选择,则会触发警报。如果您单击“Agregar Habitation”按钮创建一个selectmenu,然后在该selectmenu上进行任何选择,则不会触发警报 你知道我做错了什么吗 HTML 0 1. 0 1. Agregar Habitatió;n+ JAVASCRIPT $('#addroom').click(function() { v
0
1.
0
1.
Agregar Habitatió;n+
JAVASCRIPT
$('#addroom').click(function() {
var roomsAdd = '<section class="ui-corner-all" style="margin-top:15px;display:block;border-style:dotted; border-width:thin; padding-left:10px; padding-bottom:5px; padding-top:5px; height:40px"><input type="hidden" id="RGC" name="RGX[]" /><select style="width:50px;" id="adl" name="adl"></select><select class="ui-corner-all" style="width:50px;" id="chd" name="chd"></section>';
var myOptions = {
'0':'0', '1':'1', '2':'2', '3':'3', '4':'4', '5':'5', '6':'6'};
var RGCCNT = $('input[id^="RGC"]').length + 1;
var roomsReplace = roomsAdd.replace(/RGC/g, 'RGC_' + RGCCNT);
roomsReplace = roomsReplace.replace(/adl/g, 'adl_' + RGCCNT);
roomsReplace = roomsReplace.replace(/chd/g, 'chd_' + RGCCNT);
roomsReplace = roomsReplace.replace(/Habitacion/g, 'Habitación ' + RGCCNT);
$( "#roomselector" ).append(roomsReplace);
$('select').selectmenu();
var mySelect = $('#chd_' + RGCCNT);
$.each(myOptions, function(val, text) {
mySelect.append($('<option></option>').val(val).html(text));
});
var mySelect = $('#adl_' + RGCCNT);
$.each(myOptions, function(val, text) {
mySelect.append($('<option selected></option>').val(val).html(text));
});
$('#adl_' + RGCCNT).val(1).selectmenu('refresh');
$('#chd_' + RGCCNT).val(0).selectmenu('refresh');
return true;
});
$('select').selectmenu();
$('select').on('selectmenuchange', function() {
alert( 'x');
});
$('addroom')。单击(函数(){
var roomsAdd=“”;
变量myOptions={
'0':'0', '1':'1', '2':'2', '3':'3', '4':'4', '5':'5', '6':'6'};
var RGCCNT=$('input[id^=“RGC”]”)。长度+1;
变量roomsReplace=roomsAdd.replace(/RGC/g,'RGC_'+RGCCNT);
roomsReplace=roomsReplace.replace(/adl/g,'adl_'+RGCCNT);
roomsReplace=roomsReplace.replace(/chd/g,'chd_'+RGCCNT);
roomsReplace=roomsReplace.replace(/Habitacion/g,'Habitació;n'+RGCCNT);
$(“#roomselector”).append(roomsReplace);
$('select')。selectmenu();
var mySelect=$('chd'+RGCCNT);
$.each(myOptions,function(val,text){
追加($('').val(val.html(text));
});
var mySelect=$('adl#uuu'+RGCCNT);
$.each(myOptions,function(val,text){
追加($('').val(val.html(text));
});
$('adl'+RGCCNT).val(1)。选择菜单('refresh');
$('chd'+RGCCNT).val(0)。选择菜单('refresh');
返回true;
});
$('select')。selectmenu();
$('select')。在('selectmenuchange',function()上{
警报('x');
});
在一个完美的世界中,您应该使用,但由于您使用的是触发自定义事件的自定义组件,因此我们唯一的选择是将事件附加到新添加的选项
请考虑以下片段:
$('addroom')。单击(函数(){
var roomsAdd=“”;
变量myOptions={
'0': '0',
'1': '1',
'2': '2',
'3': '3',
'4': '4',
'5': '5',
'6': '6'
};
var RGCCNT=$('input[id^=“RGC”]”)。长度+1;
变量roomsReplace=roomsAdd.replace(/RGC/g,'RGC_'+RGCCNT);
roomsReplace=roomsReplace.replace(/adl/g,'adl_'+RGCCNT);
roomsReplace=roomsReplace.replace(/chd/g,'chd_'+RGCCNT);
roomsReplace=roomsReplace.replace(/Habitacion/g,'Habitació;n'+RGCCNT);
$(“#roomselector”).append(roomsReplace);
变量$select=$('select')。selectmenu();
var mySelect=$('chd'+RGCCNT);
$.each(myOptions,function(val,text){
追加($('').val(val.html(text));
});
var mySelect=$('adl#uuu'+RGCCNT);
$.each(myOptions,function(val,text){
追加($('').val(val.html(text));
});
$('adl'+RGCCNT).val(1)。选择菜单('refresh');
$('chd'+RGCCNT).val(0)。选择菜单('refresh');
//将事件侦听器附加到新的select。
$select.on('selectmenuchange',selectChangeCb);
返回true;
});
//所有选择的通用回调。
函数selectChangeCb(){
警报('x');
}
//初始化第一个选择。
$(“选择”)
.选择功能表()
.on('selectmenuchange',selectChangeCb)代码>
0
1.
2.
3.
4.
5.
6.
0
1.
2.
3.
4.
5.
6.
Agregar Habitatió;n+
@PabloLionelArturi很乐意帮忙!
$('#addroom').click(function() {
var roomsAdd = '<section class="ui-corner-all" style="margin-top:15px;display:block;border-style:dotted; border-width:thin; padding-left:10px; padding-bottom:5px; padding-top:5px; height:40px"><input type="hidden" id="RGC" name="RGX[]" /><select style="width:50px;" id="adl" name="adl"></select><select class="ui-corner-all" style="width:50px;" id="chd" name="chd"></section>';
var myOptions = {
'0':'0', '1':'1', '2':'2', '3':'3', '4':'4', '5':'5', '6':'6'};
var RGCCNT = $('input[id^="RGC"]').length + 1;
var roomsReplace = roomsAdd.replace(/RGC/g, 'RGC_' + RGCCNT);
roomsReplace = roomsReplace.replace(/adl/g, 'adl_' + RGCCNT);
roomsReplace = roomsReplace.replace(/chd/g, 'chd_' + RGCCNT);
roomsReplace = roomsReplace.replace(/Habitacion/g, 'Habitación ' + RGCCNT);
$( "#roomselector" ).append(roomsReplace);
$('select').selectmenu();
var mySelect = $('#chd_' + RGCCNT);
$.each(myOptions, function(val, text) {
mySelect.append($('<option></option>').val(val).html(text));
});
var mySelect = $('#adl_' + RGCCNT);
$.each(myOptions, function(val, text) {
mySelect.append($('<option selected></option>').val(val).html(text));
});
$('#adl_' + RGCCNT).val(1).selectmenu('refresh');
$('#chd_' + RGCCNT).val(0).selectmenu('refresh');
return true;
});
$('select').selectmenu();
$('select').on('selectmenuchange', function() {
alert( 'x');
});