removeAttr is not working as everything is correct
<input name="phoneno" type="text" class="configradio" id="phoneinput" size="40" data-required="true" data-fixlength10="[10]" data-type="digits"/>
$('#auth_type').on('change',function(){
var typename=document.getElementById('auth_type').value;
$('#resultform').parsley('destroy');
if(typename=="some value"){
$('#phoneinput').removeAttr('data-required');
}
else{
$('#phoneinput').Attr('data-required',true);
}
$('#resultform').parsley();
});
please provide some feedback.
instead of removeAttr()
use removeData()
:
$('#phoneinput').removeData('required');
Also here is a syntax error Attr
a is a uppercase which should be lowercase attr
, instead use prop
, because this is setting the boolean value:
$('#phoneinput').prop('data-required',true);
or better to use data()
:
$('#phoneinput').data('required', true);
Try with this code:
$('#auth_type').on('change', function () {
var typename = this.value;
$('#resultform').parsley('destroy');
if (typename == "some value") {
$('#phoneinput').removeData('required');
} else {
$('#phoneinput').data('required', true);
}
$('#resultform').parsley();
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.