[英]How to add headers,checkboxes and submit/cancel button to form table php?
[英]cancel button php form jquery
這些是我表單上的按鈕:
<input type="submit" id="form-submit" class="btn" name="save" value="verzenden" />
<input type="submit" name="cancel" class="btn" value="annuleren" />
我用php捕獲了取消點擊,如下所示:
if($_POST['cancel'])
{
Helper::redirect('page.php');
}
但是在提交表單之前,我使用了一些jQuery來驗證表單,現在我無法單擊“取消”,因為它將首先進行驗證。
這是我的jQuery代碼:
<script type="text/javascript">
$(document).ready(function(){
$('#cancel').delegate('','click change',function(){
console.log('test');
});
$('form').submit(function(){
var proceed = true;
$('.required').each(function(){
if ($(this).val() == '' || $(this).val() == 0 || $(this).val() == '0') {
$(this).css('border-color', '#F00');
proceed = false;
}
else {
$(this).css('border-color', '#999');
}
});
return proceed;
});
// Check on typing if a required field is empty
$('.required').keyup(function(){
if ($(this).val() == '' || $(this).val() == 0 || $(this).val() == '0' )
$(this).css('border-color', '#F00');
else
$(this).css('border-color', '#999');
});
});
</script>
當我點擊取消時,如何忽略jQuery並重定向到page.php? 謝謝
$('#cancel').delegate('','click change',function(){
console.log('test');
});
當您的表單中沒有任何ID為Cancel的元素時,這將無法工作
改變那個按鈕
<input type="submit" name="cancel" class="btn" value="annuleren" />
至
<input type="submit" id="cancel" name="cancel" class="btn" value="annuleren" />
這就是我現在得到的:
感謝ThiefMaster
// javascript
$('#cancel').delegate('','click change',function(){
window.location = "testimonials.php";
return false;
});
// php
if($_POST['cancel'])
{
Helper::redirect('testimonials.php');
}
// html
<input name="cancel" type="submit" id="cancel" class="btn" value="annuleren" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.