开发者

jquery, run form

how to activate the button. If the condition is true, I want to send data through a method (POST).

<script>
$(document).ready(function(){                   
    var count = 0;
    if(count == 2)
    {
        //run form
    }
});
</script>
</head>                                                                 
<body>
<form action = "" method = "post">
<input type = "text" name = "name" />
<input type = "submit" id = "ok"/>开发者_JAVA百科
</form>


$(document).ready(function(){                   
    var count = 0;
    if(count == 2)
    {
        $("myform").submit(function(e){
             //This function is called before form is posted
             if(mycondition == true)
                return true;   //that will post the form
             else
                 return false; // that will stop posting form 

               //Here you can also change values of input fields and also do  
               // validation on them.
               // instead of return false you can also use e.preventDefault() 
               //  that will stop this event to do what it usually does that
                // is submit the form.
           }).trigger("submit"); //if you want it to submit immediatly
        }
    });

OR if you dont wanna use form id then

 $(document).ready(function(){                   
        var count = 0;
        if(count == 2)
        {
            $("body form").find(":input[type=submit][id=ok]").trigger("click");
        }
    });

    <form action = ""  method = "post">
    <input type = "text" name = "name" />
    <input type = "submit" id = "ok"/>
    </form>


Try

$("#ok").trigger("click");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜