开发者

How to assign a value to a variable in JQUERY

开发者 https://www.devze.com 2023-01-26 10:21 出处:网络
if($(\'#error-email-id\').val() === \'\' || ($(\"#error-email-id\").val()) === \'Please enter email ID\' ||
if($('#error-email-id').val() === '' || 
  ($("#error-email-id").val()) === 'Please enter email ID' || 
  (!filter.test($("#error-email-id").val())) )

{

here I want that the the 开发者_开发技巧value in the field remains "Please Enter email id". But When I enter wrong id say "afafaf.com" then after validating it remains "afafaf.com" But I want if it fails the validation it should be "Please Enter email id"

 return false;
}


You can set the value using .val(value) method

$("#error-email-id").val("Please enter email ID");


Then just set it as value:

if( /* ... lots of conditions here ... */) {
   $("#error-email-id").val('Please enter email ID'); 
   return false;
}

See the documentation of .val().


Assign it explicitly inside your validation

$("#error-email-id").val('Please enter email ID') 
0

精彩评论

暂无评论...
验证码 换一张
取 消