【问题标题】:jQuery UI Dialog is not opening second time, but background is inaccessiblejQuery UI 对话框没有第二次打开,但背景无法访问
【发布时间】:2015-01-09 10:52:02
【问题描述】:

使用 JSTL foreach 标签生成对话框。

我第一次尝试打开对话框(其中任何一个)时,它可以正常打开,但第二次尝试打开它时,背景变为灰色并且由于对话框为模态而无法访问,但未显示对话框窗口.

这个问题有很多问题,我阅读了很多,但据我了解,没有一个描述这种情况。

这是我的 HTML:

<button id="buttonAddTask${category.id}" class="buttonAddTask">Add Task</button>

...

<div id="dialog${category.id}" title="Create new task" class="task-dialog">
<form:form id="taskForm${category.id}"
    action="${contextPath}/someAction"
     method="POST" modelAttribute="someAttribute">
     <fieldset>
        <form:input type="text" path="taskName" id="taskName" 
             class="text ui-widget-content ui-corner-all" />
        <form:textarea rows="4" path="taskDescription"
                 id="taskDescription" name="taskDescription"
                 class="text ui-widget-content ui-corner-all">
        </form:textarea>
    </fieldset>
</form:form>
</div>

这是我的 js 代码:

$(function() {

    var form;
    var taskDialog = $(".task-dialog");
    var buttonAddTask = $(".buttonAddTask");

taskDialog.dialog({
    autoOpen : false,
    height : 500,
    width : 415,
    modal : true,
    buttons : {
        "Create task" : addTask,
        Cancel : function() {
            taskDialog.dialog("close");
        }
    },
    close : function() {
        var form = $(this).find("form")[0].reset();
        allFields.removeClass("ui-state-error");
        }
    });

    function addTask() {
        var thisId = $(this).attr("id").substring(6, 106);
        $("#taskForm" + thisId).submit();
        return true;
    }

buttonAddTask.on("click", function() {
        var thisId = $(this).attr("id");
        var idNumber = thisId.substring(13, 14);
        $("#dialog" + idNumber).dialog("open");
    });
});

我用 .dialog("open") 打开对话框,然后关闭它。 Dialog 是通过 id 选择器访问的,所以在它移动到 body 标签的末尾后应该是可以访问的。我做错了什么或者我必须做什么才能第二次显示对话框?

我正在使用 jQuery 2.1.1 和 jQuery-ui 1.11.2。

【问题讨论】:

    标签: javascript jquery html jquery-ui jstl


    【解决方案1】:

    过了一会儿我就知道了。

    这是从一些示例中复制/粘贴的,并且已根据我的需要进行了修改。诀窍是在关闭函数中删除未声明的变量“allFields”。

    要删除的行:

    allFields.removeClass("ui-state-error");
    

    如果您有类似的问题,请检查您的关闭函数是否有未声明的变量,并将其删除。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-27
      • 2011-08-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多