[英]How to show message in hidden field using jQuery?
我有一個輸入字段存儲用於檢查條件的值。我將其更改為隱藏:如果條件為false,我需要顯示一條消息。
如果該字段被隱藏,則不顯示該消息。
HTML
<input type="hidden" id="year1_req_fund_hidden" name="year1_req_fund_hidden">
jQuery的
#wizard5').validate(
{
rules: {
year1_req_fund_hidden:{
//required:true,
number:true,
validate_check: [$('#year1_grand_amt').val(),'1'],
},
},
});
$.validator.addMethod("validate_check",
function(value, element, params) {
if(params[0]!=''){
if(value == params[0]) {
return true;
}
}
},
$.format("The total amount requested does not match with grant amount {0} requested in Q1.11 in year {1} .")
);
$('#wizard5').validate({
ignore:'', // or ignore: []
rules: {
year1_req_fund_hidden:{
//required:true,
number:true,
validate_check: [$('#year1_grand_amt').val(),'1'],
},
},
});
您的代碼應如上所述
它會對你有用。 默認情況下,jQuery Validation會忽略隱藏字段。 http://prntscr.com/g0urkk
這種方式可以解決你的問題......!
if (!$('input').attr('id') == null) { //check your condition according to you //your action here } else { //show your message in .hidden div $('.hidden').fadeIn('slow').html('Message'); }
.hidden {display: none;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="hidden" id="year1_req_fund_hidden" name="year1_req_fund_hidden"> <!-- Place below div where you want to show your message --> <div class="hidden"></div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.