如果没有警告框,Jquery 无法正常工作
如果我问的是重复或常见的问题,请忽略。
如果我在代码中有警报,Jquery 工作正常。
示例:
var selectedEvent = jQuery("#DemoEvents").jqGrid('getGridParam','selrow');
var imagePath = jQuery("#DemoEvents").getCell(selectedEvent, 9);
var locationArr = imagePath.split("rel");
var evtId = jQuery("#DemoEvents").getCell(selectedEvent, 0);
**alert(evtId);**
var anchorId = jQuery("#DemoEvents").getCell(selectedEvent, 7);
jQuery('#tr_anchorId .FormElement').val(anchorId);
jQuery("#tr_anchorId .FormElement option[value='"+evtId+"']").remove();
工作正常...并且...
var selectedEvent = jQuery("#DemoEvents").jqGrid('getGridParam','selrow');
var imagePath = jQuery("#DemoEvents").getCell(selectedEvent, 9);
var locationArr = imagePath.split("rel");
var evtId = jQuery("#DemoEvents").getCell(selectedEvent, 0);
**//alert(evtId);**
var anchorId = jQuery("#DemoEvents").getCell(selectedEvent, 7);
jQuery('#tr_anchorId .FormElement').val(anchorId);
jQuery("#tr_anchorId .FormElement option[value='"+evtId+"']").remove();
不工作。任何想法请给出。
Please ignore if I am asking a repeated or common question.
Jquery is working fine if i have an alert in the code.
Example:
var selectedEvent = jQuery("#DemoEvents").jqGrid('getGridParam','selrow');
var imagePath = jQuery("#DemoEvents").getCell(selectedEvent, 9);
var locationArr = imagePath.split("rel");
var evtId = jQuery("#DemoEvents").getCell(selectedEvent, 0);
**alert(evtId);**
var anchorId = jQuery("#DemoEvents").getCell(selectedEvent, 7);
jQuery('#tr_anchorId .FormElement').val(anchorId);
jQuery("#tr_anchorId .FormElement option[value='"+evtId+"']").remove();
is working fine... and....
var selectedEvent = jQuery("#DemoEvents").jqGrid('getGridParam','selrow');
var imagePath = jQuery("#DemoEvents").getCell(selectedEvent, 9);
var locationArr = imagePath.split("rel");
var evtId = jQuery("#DemoEvents").getCell(selectedEvent, 0);
**//alert(evtId);**
var anchorId = jQuery("#DemoEvents").getCell(selectedEvent, 7);
jQuery('#tr_anchorId .FormElement').val(anchorId);
jQuery("#tr_anchorId .FormElement option[value='"+evtId+"']").remove();
is not working. any ideas please give.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不起作用的唯一原因是您的方法中有 AJAX 调用。
在此代码段上放置
警报
可为 AJAX 调用提供时间来获取数据。否则它将无法工作,因为代码片段在 AJAX 调用返回之前就已耗尽。如果存在 AJAX 调用,那么理想情况下您应该在其回调方法中编写其余代码,这将解决问题。
PS:我对
getCell
的看法是错误的。它是一个 jqGrid 方法。对不起。The only reason it should not be working is because there is an AJAX call in your method.
Placing an
alert
on this snippet gives time for that AJAX call to fetch your data. Otherwise it won't work because the snippet runs out before your AJAX call returns.If there is an AJAX Call then you should ideally be writing the rest of the code in its call back method and this would solve the issue.
P.S: I was wrong about
getCell
. Its a jqGrid method. Sorry.