jquery ui 对话框无法打开
我试图在用户单击锚链接后打开 Jquery UI 对话框。
我正在使用 Jquery 1.5.2 和 UI 1.8.11,并且没有收到任何错误消息。我正在遵循此页面上的示例: jquery ui 对话框文档
我的 JS:
$(document).ready(function() {
$('#payTypeOptions').dialog({
autoOpen: false,
height:600,
width: 600,
modal: true
});
$('#showPayTypeOptions').click(function(){
$('#payTypeOptions').dialog('open');
//If I put an alert() here, the alert shows
});
});
HTML :
<a id="showPayTypeOptions">Do something</a>
<div id="payTypeOptions">
<p>Content</p>
</div>
谢谢。
编辑:代码没有任何问题。这是导入过程中的用户错误 - doh!
I'm trying to open a Jquery UI dialog box after the user clicks on an anchor link.
I'm using Jquery 1.5.2 and UI 1.8.11 and am getting no error messages. I am following the example on this page: jquery ui dialog documentation
My JS:
$(document).ready(function() {
$('#payTypeOptions').dialog({
autoOpen: false,
height:600,
width: 600,
modal: true
});
$('#showPayTypeOptions').click(function(){
$('#payTypeOptions').dialog('open');
//If I put an alert() here, the alert shows
});
});
The HTML:
<a id="showPayTypeOptions">Do something</a>
<div id="payTypeOptions">
<p>Content</p>
</div>
Thanks.
Edit: There was nothing wrong with the code. It was user error in the import process - doh!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我以前也遇到过这种情况,这与进口有关。
要查看是否是这种情况,请尝试以下脚本和样式。
尝试:
I've had this happen to me before too and it had to do with the imports.
To see if that's the case, try the following scripts and styles.
try:
试试这个:
看看是否会打开模式。如果是这样,那么您需要先声明模态块,然后再尝试打开它。
Try this:
See if that opens the modal. If it does then you'll need to declare the modal piece first before you try to open it.
我认为,您必须交换它们,首先创建对话框,然后调用它。
You have to swap them around, I think, where you're creating the dialog box first, then calling it up.
创建像这里这样的函数 http://pluksza.blogspot .com/2011/06/jquery-ui-dialog-open-good-practise.html 并将事件绑定到按钮
Create function like here http://pluksza.blogspot.com/2011/06/jquery-ui-dialog-open-good-practise.html and bind event to button
我遇到了非常相似的问题,但我的模式打开了一瞬间,然后就消失了。当我单击“打开对话框”按钮时,我通过观察 Chrome 开发工具 Elements 选项卡中的 HTML 变化来找到解决方案。您必须记住,如果单击的元素是按钮或链接,则返回 false,否则您的页面将再次发布或获取,并且您会丢失对话框。所以我的代码看起来像这样:
希望这对某人有帮助
I had a very similar problem but my modal opened for a split second and then disappeared. I worked out the solution by watching the HTML change in the Chrome dev tool Elements tab as I clicked on my "open the dialog" button. You have to remember to return false from the clicked element, if it's a button or link, otherwise your page will be posted or get'ed again and you lose your dialog. So my code would look something like:
Hope this helps someone
尝试将对话框存储在变量中并引用它。我已经成功地这样做了:
Try storing the dialog in a variable and referencing that. I've had success doing it this way:
一旦你声明了对话框(在“打开”之前),你可以使用 DOM 检查器(firebug)来检查 div 吗?声明对话框后,您应该会看到 jQuery 创建的许多附加标记。 ui-widget、ui-dialog 等...
Once you declare the dialog (before you 'open') can you use a DOM inspector (firebug) to review the div? Once the dialog is declared you should see a lot of additional markup created by jQuery. ui-widget, ui-dialog, etc...