除非我先调用alert(),否则覆盖 JQuery 中的选择框将不起作用?
我正在使用 JQuery Modal 显示一个带有表单的弹出窗口。我的控制面板中的所有下拉框都是使用 jquery 插件更改的,通常工作正常。为了让 Javascript 与模态一起工作,我需要执行回调,但我得到了奇怪的结果。
当我打开模式时,如果我在更改选择之前放置警报,我只会看到正确的下拉框:
回调:
var myOpen = function(hash){
hash.w.css('opacity',1).show();
alert("test"); //This will make the selects change properly.
$('select').selectmenu();
};
模式打开:
$('a#settings').click(function(){
var script = 'myLink.php';
$('#ex2').jqm({ajax: script, onShow: myOpen});
$('#ex2').jqmShow({modal: true});
});
我想这与加载时间量有关模态,因为添加警报可以让 JS 有更多的时间来处理,但这看起来很奇怪。
我错过了什么吗?
编辑:如果我非常快地单击警报“确定”按钮,选择也不会改变,这证实了我对警报允许 JS 处理时间的想法(尽管我仍然觉得很奇怪)。
I am using JQuery Modal to show a popup with a form in. All the drop down boxes in my control panel are changed using a jquery plugin which generally works fine. To get Javascript to work with the modal I need to do a callback but I am getting odd results.
When I open the modal, I will only see the correct drop down box IF I put an alert in just before the select's are changed:
The Callback:
var myOpen = function(hash){
hash.w.css('opacity',1).show();
alert("test"); //This will make the selects change properly.
$('select').selectmenu();
};
The modal open:
$('a#settings').click(function(){
var script = 'myLink.php';
$('#ex2').jqm({ajax: script, onShow: myOpen});
$('#ex2').jqmShow({modal: true});
});
I guess this is something to do with the amount of time to load the modal because adding the alert in allows more time for the JS to process but this just seems odd.
Am I missing something?
EDIT: If I click the alert "Ok" button very fast the select doesn't change either which confirms my thought of the alert allowing the time for the JS to process (although I still find that odd).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,成功地通过在 onLoad 事件中调用
.selectmenu
而不是 onShow 来对此进行排序。最终代码类似于:
Ok, managed to sort this by calling the
.selectmenu
in the onLoad event instead of the onShow.Final code is something like: