我想使用jqueryui按鈕提交表單。我有一些代碼,但它不起作用。下面是代碼:我如何使用jqueryui按鈕提交表單,
<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>
當一個人把文本區域的鏈接並提交形式,jQuery的對話框,其中顯示三個按鈕,我想,當有人點擊對話框中的「是」按鈕,表單自動提交。一切工作正常。但是當我點擊按鈕是的,它不起作用。
首先,你調用了函數submit_form(),但是你已經定義了函數submi_form()。如果你使用jQuery,你爲什麼使用'var formSubmit = document.getElementById('formSubmit');'?爲什麼不使用'$('#formSubmit')'? – mittmemo
如果是關於jQuery UI? – dmi3y
什麼是不工作'findUrls()'或'show_box()'函數? –