admin管理员组文章数量:1415467
I want to use jQuery dialog to open answer form in a modal dialog. After loading page, for the first time, it's ok, but after that by each click it will open 2^n-1
times!!! (n
is count of clicks)
something like this:
click-> open dialog (1 time) -> close dialog
click-> open dialog (2 times) -> close dialog
click-> open dialog (4 times) -> close dialog
click-> open dialog (8 times) -> close dialog
this is the code:
$(function () {
$('label.answer').click(function (event) { openInDialog(this, event, 'http://localhost/Questions/Answer/2') });
});
function openInDialog(element, event, target)
{
event.preventDefault();
var $loading = $('<img src="../../Others/images/ajaxLoading.gif" alt="loading" class="ui-loading-icon">');
var $url = target;
var $title = "Title";
var $dialog = $('<div></div>');
$dialog.empty();
$dialog
.append($loading)
.load($url)
.dialog(
{
autoOpen: false
, title: $title
, modal: true
, show: 'fade'
, hide: 'fade'
});
$dialog.dialog('open');
};
I want to use jQuery dialog to open answer form in a modal dialog. After loading page, for the first time, it's ok, but after that by each click it will open 2^n-1
times!!! (n
is count of clicks)
something like this:
click-> open dialog (1 time) -> close dialog
click-> open dialog (2 times) -> close dialog
click-> open dialog (4 times) -> close dialog
click-> open dialog (8 times) -> close dialog
this is the code:
$(function () {
$('label.answer').click(function (event) { openInDialog(this, event, 'http://localhost/Questions/Answer/2') });
});
function openInDialog(element, event, target)
{
event.preventDefault();
var $loading = $('<img src="../../Others/images/ajaxLoading.gif" alt="loading" class="ui-loading-icon">');
var $url = target;
var $title = "Title";
var $dialog = $('<div></div>');
$dialog.empty();
$dialog
.append($loading)
.load($url)
.dialog(
{
autoOpen: false
, title: $title
, modal: true
, show: 'fade'
, hide: 'fade'
});
$dialog.dialog('open');
};
Share
Improve this question
edited Dec 10, 2011 at 5:55
Marcus Adams
54k9 gold badges97 silver badges145 bronze badges
asked May 25, 2011 at 9:15
AlirezaAlireza
1421 gold badge4 silver badges13 bronze badges
3
-
var $dialog = $('<div></div>');
doesn't look fishy to you? ;) – Michael J.V. Commented May 25, 2011 at 9:20 - @Alireza: Colleague, not college (sue me for a spelling error). m-w.info/dictionary/colleague I'm just giving you an opinion, based on having participated here a lot, that that level of slang is inappropriate and disrespectful. – T.J. Crowder Commented May 25, 2011 at 12:17
- @T.J. Crowder - Thank you, I wont use slang anymore. – Alireza Commented May 25, 2011 at 13:01
1 Answer
Reset to default 4initialize the dialog outside of the function. You should also not try to open the dialog until the success of the load.
$(function () {
$('label.answer').click(function (event) { openInDialog(this, event, 'http://localhost/Questions/Answer/2') });
});
var $dialog = $('<div></div>').dialog(
{
autoOpen: false
, modal: true
, show: 'fade'
, hide: 'fade'
});
function openInDialog(element, event, target)
{
event.preventDefault();
var $loading = $('<img src="../../Others/images/ajaxLoading.gif" alt="loading" class="ui-loading-icon">');
var $url = target;
var $title = "Title";
$dialog.empty();
/* this is incorrect $dialog.dialog({ "option", "title",$title})*/
$dialog.dialog("option", "title",$title)
.append($loading)
.load($url,function(){
$dialog.dialog('open');
});
};
本文标签: javascriptWhy does my modal jQuery dialog open multiple timesStack Overflow
版权声明:本文标题:javascript - Why does my modal jQuery dialog open multiple times? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745231547a2648844.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论