這裏完整的例子是一種資源,你可以編輯和使用 下載源代碼或在這裏觀看現場演示 http://purpledesign.in/blog/pop-out-a-form-using-jquery-and-javascript/
A DD按鈕或鏈接到您的網頁這樣
<p><a href="#inline">click to open</a></p>
「#inline」這裏應該是的「ID」將包含的形式。
<div id="inline">
<h2>Send us a Message</h2>
<form id="contact" name="contact" action="#" method="post">
<label for="email">Your E-mail</label>
<input type="email" id="email" name="email" class="txt">
<br>
<label for="msg">Enter a Message</label>
<textarea id="msg" name="msg" class="txtarea"></textarea>
<button id="send">Send E-mail</button>
</form>
</div>
包含這些腳本來監聽點擊事件。如果你已經在你的形式的操作定義,您可以使用「的preventDefault()」方法
<script type="text/javascript">
$(document).ready(function() {
$(".modalbox").fancybox();
$("#contact").submit(function() { return false; });
$("#send").on("click", function(){
var emailval = $("#email").val();
var msgval = $("#msg").val();
var msglen = msgval.length;
var mailvalid = validateEmail(emailval);
if(mailvalid == false) {
$("#email").addClass("error");
}
else if(mailvalid == true){
$("#email").removeClass("error");
}
if(msglen < 4) {
$("#msg").addClass("error");
}
else if(msglen >= 4){
$("#msg").removeClass("error");
}
if(mailvalid == true && msglen >= 4) {
// if both validate we attempt to send the e-mail
// first we hide the submit btn so the user doesnt click twice
$("#send").replaceWith("<em>sending...</em>");
//This will post it to the php page
$.ajax({
type: 'POST',
url: 'sendmessage.php',
data: $("#contact").serialize(),
success: function(data) {
if(data == "true") {
$("#contact").fadeOut("fast", function(){
//Display a message on successful posting for 1 sec
$(this).before("<p><strong>Success! Your feedback has been sent, thanks :)</strong></p>");
setTimeout("$.fancybox.close()", 1000);
});
}
}
});
}
});
});
</script>
您可以添加你想要在你的PHP文件做任何事情。
Google「Javascript Modals」或「JQuery Modals」 – 2011-06-07 13:28:27
我相信「無法更改[popup]內容」評論指的是_redirect-preventing_upups。出於明顯的安全原因,該消息通常被瀏覽器覆蓋。下面是一個演示問題的小提琴:http://jsfiddle.net/k2fYM/ – 2014-01-27 11:51:48