我如何使用jqueryui对话框按钮提交表单, [英] How do i submit a form with jqueryui dialog button,

查看:96
本文介绍了我如何使用jqueryui对话框按钮提交表单,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用jqueryui按钮提交表单。我有一些代码,但它不起作用。以下是代码:

 < script type =text / javascript> 
函数findUrls()
{
var text = document.getElementById(text)。value;
var source =(text ||'').toString();
var urlArray = [];
var url;
var matchArray;

//用于查找FTP,HTTP(S)和电子邮件URL的正则表达式。
var regexToken = /\b(http|https)?(:\/\//?(\S*)\.(\w{2,4} )\b/ IG;

//遍历文本中的任何URL。
if((regexToken.exec(source))!== null)
{
show_box(); //这将显示jquery dialog ..
return false;
}

}

< / script>

< div id =dialogtitle =对话框标题>
< p>对话框文字.....对话框文字....对话框文字< / p>
< button id =formSubmit>点击我< /按钮>
< / div>

< form name =myFormid =myFormaction =http://www.bing.commethod =postonsubmit =return findUrls();>
< textarea id =text>< / textarea>
< input type =submitname =submitvalue =send/>
< / form>

< script type =text / javascript>
函数show_box(){
$(document).ready(function(){
$ b $(#dialog).dialog({
autoOpen:false ,
width:400,
buttons:[
{
text:Yes,
click:function(){
submit_form();



$ b text:否,
click:function(){
$(this).dialog( close);
}
},
{
text:取消,
click:function(){
$(this)。对话框(关闭);
}
}
]
});

$( #dialog).dialog(open);
});
}

函数submi_form(){
var myForm = document.forms ['myForm'];

var formSubmit = document.getElementById('formSubmit');

formSubmit.onclick = function(){
myForm.submit();
}
}
< / script>

当一个人在文本区域放置一个链接并提交表单时,jquery对话框显示为三按钮,我希望当有人点击对话框上的是按钮时,表单会自动提交。一切工作正常。但是,当我点击按钮yes,它不起作用。

解决方案

您的submit_form函数实际上并未尝试提交表单。它现在正在向Click Me按钮添加点击事件,如果按下该按钮,则会提交您的表单。



如果您想单击对话框中的是按钮提交表单,试试这个:

$ p $ function submit_form(){
$('#myForm')。submit ();
}

另外请确保您的submi_form方法的名称在这里只是一个错字,而不是在您的实时代码中...您错过了t。


I want to submit a form using jqueryui button. I had some code but it doesn't work. Here is the code:

<script type="text/javascript">
function findUrls()
{
    var text = document.getElementById("text").value;
    var source = (text || '').toString();
    var urlArray = [];
    var url;
    var matchArray;

    // Regular expression to find FTP, HTTP(S) and email URLs.
    var regexToken = /\b(http|https)?(:\/\/)?(\S*)\.(\w{2,4})\b/ig;

    // Iterate through any URLs in the text.
    if( (regexToken.exec( source )) !== null )
    {
    show_box();// this will show jquery dialog..
    return false;
    }

}

</script>

<div id="dialog" title="Dialog Title">
<p>Dialog box text.....Dialog box text....Dialog box text</p>
<button id="formSubmit">Click me</button>
</div>

<form name="myForm" id="myForm" action="http://www.bing.com" method="post" onsubmit="return findUrls();"> 
<textarea id="text"></textarea>
<input type="submit" name="submit" value="send" />
</form>

<script type="text/javascript">
function show_box(){
$(document).ready(function(){

                $( "#dialog" ).dialog({
                autoOpen: false,
                width: 400,
                buttons: [
                    {
                        text: "Yes",
                        click: function() {
                            submit_form();

                        }
                        },
                    {
                        text: "No",
                        click: function() {
                            $( this ).dialog( "close" );
                        }
                    },
                    {
                        text: "Cancel",
                        click: function() {
                            $( this ).dialog( "close" );
                        }
                    }
                ]
            });

            $( "#dialog" ).dialog( "open" );
});
}

function submi_form(){
var myForm = document.forms['myForm'];

var formSubmit = document.getElementById('formSubmit');

formSubmit.onclick = function(){
    myForm.submit();
    }
}
</script>

When a person puts a link in text area and submit the form, the jquery dialog box appear with three buttons, I want that when some one click the "Yes" button on dialog box, the form automatically submit. Everything is working fine. But When i click the button yes, it doesn't work.

解决方案

Your submit_form function is not actually trying to submit the form. It is currently adding a click event onto the "Click Me" button which if pressed will then submit your form.

If you want clicking the "Yes" button of your dialog to submit the form, try this:

function submit_form(){
    $('#myForm').submit();
}

Also make sure the name of your submi_form method is just a typo here rather than in your live code...you are missing a "t".

这篇关于我如何使用jqueryui对话框按钮提交表单,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆