我有一個用Bootstrap編寫的輸入表單。檢查正確的數據是由javascript處理的,並且它設置爲在點擊按鈕「提醒我」時彈出一個通知,說明一切正確。彈出式通知的最後一部分由php POST方法處理,並且我想要顯示相同的彈出窗口,但使用javascript而不是php。Javascript function like php POST
的HTML是:
<form class="form-horizontal" id="registerHere" method='post' action=''>
<fieldset>
<div class="control-group">
<div class="controls">
<input type="text" class="span3" id="user_name" name="user_name" rel="popover" data-content="Enter your first and last name." data-original-title="Full Name" placeholder="First name Last name">
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="text" class="span3" id="user_email" name="user_email" rel="popover" data-content="What’s your email address?" data-original-title="Email" placeholder="[email protected]">
</div>
</div>
<div class="control-group">
<div class="controls controls-row">
<input type="text" class="span1" id="inputPLZ" name="inputPLZ" placeholder="Postal" data-content="Insert your area postal code.">
<input type="text" class="span2" id="inputOrt" name="inputOrt" placeholder="Place" data-content="Where are you from?">
</div>
</div>
<div class="control-group">
<label class="control-label" for="input01"></label>
<div class="controls">
<button type="submit" class="btn btn-success" rel="tooltip" title="first tooltip">Remind me</button>
</div>
</div>
</fieldset>
</form>
和JavaScript是
<script type="text/javascript">
$(document).ready(function(){
$('#registerHere input').hover(
function(){
$(this).popover('show')
},
function(){
$(this).popover('hide')
}
);
$("#registerHere").validate({
rules:{
user_name:"required",
user_email:{
required:true,
email: true
},
},
messages:{
user_name:"Enter your first and last name",
user_email:{
required:"Enter your email address",
email:"Enter valid email address"
},
},
errorClass: "help-inline",
errorElement: "span",
highlight:function(element, errorClass, validClass) {
$(element).parents('.control-group').addClass('error');
},
unhighlight: function(element, errorClass, validClass) {
$(element).parents('.control-group').removeClass('error');
$(element).parents('.control-group').addClass('success');
}
});
});
</script>
這是我想用javascript取代PHP部分:
<?php if($_POST) { ?>
<div class="alert alert-success">
Thanks, we have your info, and expect our contact really soon!
</div>
<?php } ?>
從[JQuery](http://jquery.com/) – DarkBee 2013-04-20 18:41:14
或$ .ajax()獲取更多選項使用[$ .post](http://api.jquery.com/jQuery.post/) – 2013-04-20 18:45:27
我不明白你到底需要什麼。任何彈出窗口都是客戶端Javascript的操作! – SaidbakR 2013-04-20 18:49:01