简体   繁体   English

jQuery select会针对不断变化的JS行为提示错误的下拉菜单选项值

[英]jquery select alerts the wrong drop-down menu option value for on-change js behavior

I have Js array that holds the values of dynamic menu. 我有保存动态菜单的值的Js数组。 The option values of menu changes with the ID of event. 菜单的选项值随事件ID改变。

There is a jQuery pop-up window which contains the form. 有一个包含表单的jQuery弹出窗口。 After loading the window, the menu options show up but the jquery does not alert the right selected value...it always shows the first item in the select options 加载窗口后,显示菜单选项,但jquery不会警告正确的选定值...它始终显示选择选项中的第一项

Go to the below link and click on "Join Event" buttons for event id=130131CHcbd and 150724CH5f1 where you see that no what event date you pick, it alerts the same date... 转到下面的链接,然后单击事件ID = 130131CHcbd和150724CH5f1的“加入事件”按钮,您会看到没有选择任何事件日期,它会提示相同的日期...

http://www.weg2g.com/application/abovezest/personal_networking.php http://www.weg2g.com/application/abovezest/personal_networking.php

I've basic knowledge of JS, so any advice or help to solve this issue... 我有JS的基础知识,因此有任何建议或帮助来解决此问题...

 <script> var jArray= {"150724CH5f1":"<option value=\\"2017-01-27\\" id=\\"1\\"> Fri Jan 27th 2017<\\/option> <option value=\\"2017-02-03\\" id=\\"2\\"> Fri Feb 3rd 2017<\\/option> <option value=\\"2017-02-10\\" id=\\"3\\"> Fri Feb 10th 2017<\\/option> <option value=\\"2017-02-17\\" id=\\"4\\"> Fri Feb 17th 2017<\\/option> <option value=\\"2017-02-24\\" id=\\"5\\"> Fri Feb 24th 2017<\\/option>","130131CHcbd":"<option value=\\"2017-01-28\\" id=\\"1\\"> Sat Jan 28th 2017<\\/option> <option value=\\"2017-02-04\\" id=\\"2\\"> Sat Feb 4th 2017<\\/option> <option value=\\"2017-02-11\\" id=\\"3\\"> Sat Feb 11th 2017<\\/option> <option value=\\"2017-02-18\\" id=\\"4\\"> Sat Feb 18th 2017<\\/option> <option value=\\"2017-02-25\\" id=\\"5\\"> Sat Feb 25th 2017<\\/option>"}; //get all function bind_event_dates(v,type) { //alert(jArray[v]); var w=jArray[v]; //var y="'"+v+"'"; if (type==3) { var str1='<select name="edate" id="edate_bn_d" onchange="check_e_date(3);" required>'; } // //append the other parts var str2=str1.concat(w); var str3='</select>'; var kk=str2.concat(str3); //alert(rrr); $("#load_dates3").html(kk); }//end of binding event dates //-------------------------------------- function check_e_date(a) { if (a==3) { var wanted=$("#edate_bn_d").val(); //always select the first option of select menue alert(wanted); $("#bn_roomatte").val(wanted) } }//end of check event date function //----------------------------------------------------------------------------- // </script> 

I have edit code javascript. 我有JavaScript的编辑代码。 It has working. 它有工作。

 var jArray= {"150724CH5f1":"<option value=\\"2017-01-27\\" id=\\"1\\"> Fri Jan 27th 2017<\\/option> <option value=\\"2017-02-03\\" id=\\"2\\"> Fri Feb 3rd 2017<\\/option> <option value=\\"2017-02-10\\" id=\\"3\\"> Fri Feb 10th 2017<\\/option> <option value=\\"2017-02-17\\" id=\\"4\\"> Fri Feb 17th 2017<\\/option> <option value=\\"2017-02-24\\" id=\\"5\\"> Fri Feb 24th 2017<\\/option>","130131CHcbd":"<option value=\\"2017-01-28\\" id=\\"1\\"> Sat Jan 28th 2017<\\/option> <option value=\\"2017-02-04\\" id=\\"2\\"> Sat Feb 4th 2017<\\/option> <option value=\\"2017-02-11\\" id=\\"3\\"> Sat Feb 11th 2017<\\/option> <option value=\\"2017-02-18\\" id=\\"4\\"> Sat Feb 18th 2017<\\/option> <option value=\\"2017-02-25\\" id=\\"5\\"> Sat Feb 25th 2017<\\/option>"}; //get all function bind_event_dates(v,type) { //alert(jArray[v]); var w=jArray[v]; //var y="'"+v+"'"; if (type==3) { var str1='<select name="edate" id="edate_bn_d" onchange="check_e_date(3);" required>'; } // //append the other parts var str2=str1.concat(w); var str3='</select>'; var kk=str2.concat(str3); //alert(rrr); $("#load_dates3").html(kk); }//end of binding event dates //-------------------------------------- function check_e_date(a) { if (a==3) { var wanted=$("#edate_bn_d").val(); //always select the first option of select menue alert(wanted); $("#bn_roomatte").val(wanted) } }//end of check event date function //----------------------------------------------------------------------------- // 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> <title>Domoos mobile</title> <meta http-equiv="refresh" content="600"> <meta http-equiv="pragma" content="no-cache"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> </head> <body onload="bind_event_dates('150724CH5f1',3);"> <div id="load_dates3"> </div> </body> </html> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM