我有两个单选按钮,每个单选按钮都有文本输入字段。我添加这个 ------ 就像文本输入字段的默认值一样。我只想在检查第二个 radio 时删除此值。
我的代码是:
if (jQuery('.product-options .display ul li:nth-child(1)').find('input').is(':checked')) {
jQuery(".product-options dd input.input-text").attr('value', '--------');
jQuery(".product-options dd input.input-text").addClass('validation-passed');
}
jQuery('.product-options .display ul li:nth-child(1)').find('input').change(function(){
if (jQuery(this).is(':checked')) {
jQuery(".product-options dd input.input-text").attr('value', '--------');
jQuery(".product-options dd input.input-text").addClass('validation-passed');
}
})
jQuery('.product-options .display ul li:nth-child(2)').find('input').change(function(){
if (jQuery(this).is(':checked')) {
jQuery(".product-options dd input.input-text").attr('value', '');
}
})
最佳答案
使用 .val('')
设置输入的值,而不是 .attr('value', '')
。
关于javascript - 清除输入值 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36625438/