Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在对话框中找到的JQueryUI提交按钮仅在第二次打开对话框后有效_Jquery_Jquery Ui_Jquery Ui Dialog - Fatal编程技术网

在对话框中找到的JQueryUI提交按钮仅在第二次打开对话框后有效

在对话框中找到的JQueryUI提交按钮仅在第二次打开对话框后有效,jquery,jquery-ui,jquery-ui-dialog,Jquery,Jquery Ui,Jquery Ui Dialog,我有一个对话框,当我双击可拖动元素时会打开。其目的是在映像下面附加一个IP地址: 它可以正常工作,但只有在我关闭对话框并再次打开它,然后单击“提交”按钮之后 这是我的密码: HTML <div id="configbox" title="IPv6 Configuration" style="font-size:15px;"> <form> <b>DHCP</b> <input type="radio" name="o

我有一个对话框,当我双击可拖动元素时会打开。其目的是在映像下面附加一个IP地址:


它可以正常工作,但只有在我关闭对话框并再次打开它,然后单击“提交”按钮之后

这是我的密码:

HTML

<div id="configbox" title="IPv6 Configuration" style="font-size:15px;">
    <form>
        <b>DHCP</b> <input type="radio" name="option" value="DHCP"/> &nbsp;

        <b>Auto Config</b>  <input type="radio" name="option" value="auto"/> &nbsp;

        <b>Static</b>  <input type="radio" name="option" value="static"/> &nbsp; <br/><br/>
        <table>
            <tr>
                <td>
                    <b>IPv6 Address:</b>
                </td>
                <td>
                    <input type="text" id="address" size="25"/> &nbsp; / &nbsp; <input type="text" id="subnet" size="3"/>
                </td>
            </tr>
            <tr>
                <td>
                    <b>Link Local Address:</b>
                </td>
                <td>
                    <input type="text" id="local" size="35"/>
                </td>
            </tr>
            <tr>
                <td>
                    <b>IPv6 Gateway:</b>
                </td>
                <td>
                    <input type="text" id="gateway" size="35"/>
                </td>
            </tr>
            <tr>
                <td>
                    <b>IPv6 DNS Server:</b>
                </td>
                <td>
                    <input type="text" id="dns" size="35"/>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
        </table>
    </form>

    <center>
        <button id="submit"
                style="background-color:#B4BA22; border-radius:3px; font-size:17px; font-weight:bold; cursor:pointer;">Submit
        </button> &nbsp;
        <button id="cancel"
                style="border-radius:3px; font-size:17px; font-weight:bold; cursor:pointer;"> Cancel
        </button>
    </center>


</div>

DHCP
自动配置
静态

IPv6地址: / 链接本地地址: IPv6网关: IPv6 DNS服务器: 提交 取消
JQuery

$(document).click(function (e) {
    // matches all children of droppable, change selector as needed

    currentDragImg = $(e.target).closest(".drag");



    if ($(e.target).closest(".drag").length > 0) {

        $(e.target).closest(".drag").find(".ui-resizable-handle").show();



    }
    else {
        $("#droppable").find(".ui-resizable-handle").hide();
        $("#tools").hide();
    }


    $('.drag').dblclick(function () { //the dialog box to enter the IP address opens on double click
        $('#configbox').dialog('open');
        return false;
    });

});

/*The submit button*/
        $(function () {
            $("#submit").click(function () {
                            enter = $("#address").val();
                            $("<div>"+enter+"</div>").appendTo(currentDragImg); 
                        });
    });
$(文档)。单击(函数(e){
//匹配可拖放的所有子项,根据需要更改选择器
CurrentDragim=$(e.target).closest(“.drag”);
如果($(e.target).closest(“.drag”).length>0){
$(e.target).closest(“.drag”).find(“.ui可调整大小的句柄”).show();
}
否则{
$(“#可拖放”).find(“.ui可调整大小的句柄”).hide();
$(“#工具”).hide();
}
$('.drag').dblclick(函数(){//双击可打开输入IP地址的对话框
$('#configbox')。对话框('打开');
返回false;
});
});
/*“提交”按钮*/
$(函数(){
$(“#提交”)。单击(函数(){
输入=$(“#地址”).val();
$(“”+enter+“”)。附加到(CurrentDragim);
});
});

知道为什么会这样吗?如有任何意见,将不胜感激。谢谢。

我不确定,但你可以试试这个

起初,您的提交按钮不起作用,因为没有具有
id=submit
的元素(可能是
display:none
)。但是在您打开对话框之后,即使用
id=configbox
的元素。提交按钮也在DOM上,因此下次打开对话框时,单击事件绑定到提交按钮

您可以在打开对话框后添加click事件,如下所示

$('.drag').dblclick(function () { //the dialog box to enter the IP address opens on double click
            $('#configbox').dialog('open');
             $(function () {
                $("#submit").click(function () {
                                enter = $("#address").val();
                                $("<div>"+enter+"</div>").appendTo(currentDragImg); 
                            });
            return false;
        });
$('.drag').dblclick(函数(){//双击可打开输入IP地址的对话框
$('#configbox')。对话框('打开');
$(函数(){
$(“#提交”)。单击(函数(){
输入=$(“#地址”).val();
$(“”+enter+“”)。附加到(CurrentDragim);
});
返回false;
});

请尝试并发表评论。希望有帮助。

请分享您的全部代码。