jQuery UI Dialog没有第二次打开,但后台无法访问

时间:2015-01-09 10:52:02

标签: javascript jquery html jquery-ui jstl

使用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(“打开”)打开对话框,然后关闭它。对话框是通过id选择器访问的,因此在将其移动到body标签的末尾后应该是可以接受的。我做错了什么或者我该怎么办才能第二次显示对话框?

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

1 个答案:

答案 0 :(得分:1)

我过了一会儿。

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

删除行:

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

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

相关问题