在我的应用程序中,我需要显示一个 jQuery 对话框来提示用户输入,然后将用户提供的输入返回到页面。
在下面的代码中,我创建了所需的 HTML 以通过对话框获取用户输入,但我不知道如何将值返回到我的页面:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Dialog Box Witout Close Button</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
</head>
<body>
<button id="dialog_trigger">open the dialog</button>
<div id="dialog" style="display:none;" title="Dialog Title"><iframe width="700" height="700" src="test.html"></iframe></div>
<script>
$( "#dialog_trigger" ).click(function() {
$( "#dialog" ).dialog( "open" );
});
$("#dialog").dialog({
autoOpen: false,
position: 'center' ,
title: 'Sample Dialog',
draggable: false,
width : 500,
height : 400,
resizable : true,
buttons: {
"Ok": function() {
var firstname = $('input[name=FirstName]').val();
var lastname = $('input[name=LastName]').val();
localStorage.firstname = firstname;
localStorage.lastname = lastname;
alert("Your name is: " + lastname);
$(this).dialog("close");
}}
});
</script>
</body>
</html>
//sample.html
<html>
<head>
<script type="text/javascript">
function ExampleJS(){
var jFirst = document.getElementById("fname").value;
var jLast = document.getElementById("lname").value;
var firstname = localStorage.firstname;
var lastname = localStorage.lastname;
if(typeof(Storage)!=="undefined")
{
alert("yes");
}
else
{
alert("no");
}
localStorage.lastname="Smith";
document.getElementById("result").innerHTML="Last name: "
+ localStorage.lastname;
alert("Your name is: " + lastname);
}
</script>
</head>
<body>
<FORM NAME="myform" onSubmit="JavaScript:ExampleJS()">
First name: <input type="text" id="fname" name="firstname" /><br />
Last name: <input type="text" id="lname" name="lastname" /><br />
<input name="Submit" type="submit" value="Update" />
</FORM>
</body>
我怎样才能从中获得价值sample.html
?