我有一個表格。我想檢查表單ID。 因爲我不知道表單ID。如何用Jquery檢查表單ID?
我嘗試這樣的:
jQuery.validator.addMethod("checkDuplicate",function(value) {
var user_id = $(this).closest("form[id]").attr('id');
console.log(user_id);
var ka = $('#ID').val();
if ($("#contactpersonen_canseestock_2").is(':checked') || $("#contactpersonen_canseestock_3").is(':checked') || $("#contactpersonen_canseestock_4").is(':checked')
|| $("#contactpersonen_canseestock_5").is(':checked')) && $('#idform :checkbox:checked').length == 1) {
console.log("checkbox checked; dont check duplicate email");
return true;
}
else{
console.log("checkbox not checked; check duplicate email");
if ($("#contactpersonen_canseestock_2").is(":checked"))
{
console.log('hoi');
}
console.log(ka);
return false;
}
}, "Email adres bestaat al");
jQuery.validator.classRuleSettings.checkTotal = { checkTotal: true };
因爲#idform不是形式的ID。
但我每次都得到未定義。當我這樣做:
var user_id = $(this).closest("form[id]").attr('id');
這是形式:
http://webshop.verploegen.nl/klant-worden
,但我不能看到表格ID是什麼
這是selecter checkDuplicate:
<div class="contact-label span2">
<label for="contactpersonen-email">Email adres</label>
<div class="contact-input-field">
<input type="text" class="input-text span2 contactpersonen-email1 required checkDuplicate" id="contactpersonen_email1" name="contactpersonen_email1"></input>
</div>
</div>
貴''
請改用'var user_id = $(this).closest(「form」)。attr('id');' –
@RahulPatel你能解釋一下嗎?如果'.attr(「id」)'會起作用,那麼'$(「form [id]」)''也可以。 –