简体   繁体   English

jQuery功能代码无法正常运行

[英]JQuery Function code not running properly

I am having problems with the code below. 我下面的代码有问题。 Basically it's 2 parts in the function... 基本上它是功能的两部分...

Part 1 just clicks on a submit button and Part 2 shows a dialog. 第1部分仅单击提交按钮,第2部分显示一个对话框。

For some reason both parts run separately work but when added together in the function no dialog appears, so when together Part 2 does not run. 由于某些原因,两个部分都可以单独运行,但是将它们一起添加到功能中时,不会出现对话框,因此,当第二部分一起运行时,则不会运行。

Syntax issue? 语法问题?

Here's the code: 这是代码:

function myfunction() { 
    $('input[type=submit]#mysubmit').click();  

    $("#info").dialog({
    autoOpen: false,
    modal: true,
    width: 400,
    zIndex: 9999999,
    resizable: false,
    buttons: [
        {
            text: "Close",
            click: function () {
                $(this).dialog("close");
            }
        }
    ]
});    
}

Update: I've tried commenting out Part 1 and the dialog still doesn't show up so it's something to do with the Dialog code ... Part 2 更新:我尝试注释掉第1部分,但对话框仍然没有显示,所以这与Dialog代码有关……第2部分

See below: 见下文:

function myfunction() { 
    //$('input[type=submit]#mysubmit').click();   //commented out

    $("#info").dialog({
    autoOpen: false,
    modal: true,
    width: 400,
    zIndex: 9999999,
    resizable: false,
    buttons: [
        {
            text: "Close",
            click: function () {
                $(this).dialog("close");
            }
        }
    ]
});    
}

Try initializing and opening in 2 different places (right now, everytime you execute myfunction , the dialog gets initialized 尝试在2个不同的位置进行初始化和打开(现在,每次执行myfunction ,对话框都会初始化

$(document).ready(function(){
 $("#info").dialog({
    autoOpen: false,
    modal: true,
    width: 400,
    zIndex: 9999999,
    resizable: false,
    buttons: [
        {
            text: "Close",
            click: function () {
                $(this).dialog("close");
            }
        }
    ]
});    
});

function myfunction(){
    $("#info").dialog('open');
}

Remove autoOpen: false . 删除autoOpen: false This option causes the dialog to be rendered invisible at initialisation. 此选项使对话框在初始化时不可见。

Another option is to add .dialog("open") at the end: 另一种选择是在末尾添加.dialog("open")

$("#info").dialog(..autoOpen: false...).dialog('open');

Comparison (3x): http://jsfiddle.net/TEN7Z/2/ 比较(3倍): http : //jsfiddle.net/TEN7Z/2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM