Gop*_*oft 3 html javascript jquery jquery-ui javascript-events
我想使用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>
Run Code Online (Sandbox Code Playgroud)
当一个人在文本区域中放置一个链接并提交表单时,jquery对话框会出现三个按钮,我希望当有人单击对话框中的"是"按钮时,表单会自动提交.一切都很好.但是,当我单击按钮是,它不起作用.
您的submit_form函数实际上并未尝试提交表单.它目前在"Click Me"按钮上添加了一个点击事件,如果按下该按钮,则会提交您的表单.
如果要单击对话框的"是"按钮以提交表单,请尝试以下操作:
function submit_form(){
$('#myForm').submit();
}
Run Code Online (Sandbox Code Playgroud)
还要确保你的submi_form方法的名称只是一个错字而不是你的实时代码......你错过了一个"t".
| 归档时间: |
|
| 查看次数: |
25392 次 |
| 最近记录: |