search
HomeWeb Front-endHTML Tutorial请教jQuery:Dialog的modal状态自动解除_html/css_WEB-ITnose

jquery dialog modal状态消失

现在做的一个项目,画面上有检索,清除,追加等按钮,当追加按钮按下时,弹出jQuery的dialog。
共通js如下
var AddDialog = new function() {
  self.d = null
  this.init = function(opt){
    var o = {modal:true,..省略`..};
     for (var k in opt ){o[k]=opt[k]}
    self.d = $("#template").dialog(o);//template为div的id
    $("#btnsave").click(function(){/*共通保存方法*/});
    $("#btnclose").click(function(){/*共通关闭方法*/});
    //其他略
  }
  //其他略
}

各画面初始化时
$(function(){
  //其他略
  AddDialog.init();
  //其他略
});

这回感受jqueryDialog便利的同时,也碰到一个很奇怪的现象,很抓狂,不知道有没有人遇到过?

画面载入后,直接点追加按钮,在dialog上输入数据后,正确执行,入力检查时有错也可以在dialog的指定区域显示,modal状态也可以保持。但是,在按下检索按钮查询之后,在点追加按钮,dialog的入力项有错的时候,一切都可以正常显示,就是modal状态自动变成了false(并不是每次都这样,但是几率很大,因为不知原因,具体是哪个出了问题说不出来)。

有没有同行遇到过类似问题。麻烦诸位高人帮忙提示下调查的线索,不胜感激。

我用的jquery版本:1.5.2
ui版本为:1.8.13

我用firebug调试的时候,发现在执行我的入力检查方法之后,dialog依然是modal状态,但是在方法执行完,jquery判断是否存在其他handler之后,modal状态消失。怀疑是不是jquery的bug呢?

最后,怎样才能回避掉这个问题呢?

回复讨论(解决方案)

入力检查 代码呢?

入力检查 代码呢?

版主辛苦了,感谢。
问题已经查明白了。等晚上详细写一下,是自己程序的bug

昨天终于弄明白原因了,上面说的那些都没有用。居然是一直在用的共通部分出了问题。

1)画面的检索按钮按下的时候,会弹出一个处理中的modal-dialog(※1),然后共通JS会在检索的callback回调函数中关掉(※1)。
问题就出在这儿了,最开始的式样并没有要求弹出(※1),后来式样追加的时候,为了少改代码,将关掉(※1)的代码写在共通里面了。考虑到即使在不弹出(※1)的情况下,执行关掉(※1)的代码也不会错,关闭的代码就采取了无条件执行的写法。

2)点击追加按钮之后弹出的Modal-dialog(※2)。

在(※2)里面的按钮,按下后不需要弹出(※1)之类的东西,但是事件也会执行共通的callback回调函数。此时,在callback中,关闭(※1)的时候,就把追加的(※2)的modal状态也解除了。

对策:在关闭(※1)的时候,判断(※1)是否打开,只有在打开的情况下才执行关闭(※1)的代码。

提示:jQuery的Dialog的modal,是通过往页面body上追加一个设置了样式的DIV来实现的,所以会出现关掉(※1),remove掉这个div的同时,也把(※2)的modal状态给解除掉这种现象

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the difference between an HTML tag and an HTML attribute?What is the difference between an HTML tag and an HTML attribute?May 14, 2025 am 12:01 AM

HTMLtagsdefinethestructureofawebpage,whileattributesaddfunctionalityanddetails.1)Tagslike,,andoutlinethecontent'splacement.2)Attributessuchassrc,class,andstyleenhancetagsbyspecifyingimagesources,styling,andmore,improvingfunctionalityandappearance.

The Future of HTML: Evolution and TrendsThe Future of HTML: Evolution and TrendsMay 13, 2025 am 12:01 AM

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

Why are HTML attributes important for web development?Why are HTML attributes important for web development?May 12, 2025 am 12:01 AM

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

What is the purpose of the alt attribute? Why is it important?What is the purpose of the alt attribute? Why is it important?May 11, 2025 am 12:01 AM

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

HTML, CSS, and JavaScript: Examples and Practical ApplicationsHTML, CSS, and JavaScript: Examples and Practical ApplicationsMay 09, 2025 am 12:01 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor