嗨我无法调用 jQuery 的提交函数下面是 HTML 和 jQuery 代码
jQuery代码:
$(document).ready(function () {
//global vars
var userName = $("#username"); //user name field
var userPass = $("#password");//password field
//When form submitted
$("#overlay_form1").submit(function () {
window.alert("Please fill UserName & Password!");
return false;
});
//open popup
$("#pop").click(function () {
$("#overlay_form1").fadeIn(500);
positionPopup();
});
//close popup
$("#close").click(function () {
$("#overlay_form1").fadeOut(500);
});
});
//position the popup at the center of the page
function positionPopup() {
if (!$("#overlay_form1").is(':visible')) {
return;
}
$("#overlay_form1").css({
left : ($(window).width() - $('#overlay_form1').width()) / 2,
top : ($(window).width() - $('#overlay_form1').width()) / 7,
position : 'absolute'
});
}
//maintain the popup at center of the page when browser resized
$(window).bind('resize', positionPopup);
HTML 代码:
<a href="#" id="pop" >PopUp</a>
<br />
<form id="overlay_form1" name="overlay_form" method="post" onsubmit="return false;">
<h2> Put your contents here..</h2>
<label>Username: </label><input type="text" name="username" id="username" /><br /><br />
<label>Password: </label><input type="text" name="password" id="password"/><br /><br />
<input type="button" value="Login" />
<a href="#" id="close" >Close</a>
</form>