我正在开发一个 JavaScript,它检测文本中的链接并打开一个带有三个按钮“是”、“否”、“取消”的 JqueryUI 对话框。一切正常。当 javascript 检测到文本中的链接时,它会显示对话框。“否”和“取消”按钮工作正常。我想在用户单击“是”按钮时提交表单,但它不起作用。这是我的 HTML 和 Javascript 代码。
<script type="text/javascript">
function findUrls()
{
var text = document.forms["myForm"]["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 )
{
$(document).ready(function(){
$( "#dialog" ).dialog({
autoOpen: false,
width: 400,
buttons: [
{
text: "Yes",
click: function() {
$("#myForm").submit();
}
},
{
text: "No",
click: function() {
$( this ).dialog( "close" );
}
},
{
text: "Cancel",
click: function() {
$( this ).dialog( "close" );
}
}
]
});
$( "#dialog" ).dialog( "open" );
});
}
}
function submitform()
{
document.forms["myForm"].submit();
}
</script>
<div id="dialog" title="Dialog Title">
<p>Tes Test Test.</p>
<p><a href="javascript: submitform()">Submit</a></p>
</div>
<form name="myForm" id="myForm1" action="" onsubmit="return findUrls();">
<textarea name="text"></textarea>
<input type="submit" name="submit" id="dialog-link" value="Check it out." />
</form>