我在产品视图自定义选项中添加了两个单选按钮。以及一个依赖于单选按钮的文本输入字段。因此,当第一个单选框被选中时,第一个文本是隐藏的,我在输入文本的value属性中添加了以下字符:"-------"。当第二个单选按钮被选中时,我需要显示文本输入字段并删除值"-------"。
要将值添加到文本输入中,我使用javascript:jQuery(".product-options dd input.input-text").attr('value', '--------');
要删除我使用的值:jQuery(".product-options dd input.input-text").attr('value', '');
一切都很好,直到按下添加到购物车按钮,当我按下添加到车按钮时,我得到了这个:"Please specify the product's required option(s)."
我的代码是:
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', '');
}
})
所以我想要的是,当第一个单选框被选中并且输入文本字段被隐藏以通过验证时,在文本输入字段中添加一个默认值,当第二个单选框是选中并且文本输入字段被显示时,删除这个值。
感谢
我最近也用过同样的东西。。。(产品选项扩展)
我的建议是确保".product-options-dd-input.input-text"这适用于特定元素
-
尝试使用
jQuery('.product-options dd input.input-text').val('-------');
作为在任何地方获得一致行为的正确方式。 -
与其添加新类,不如删除
"validate-one-required-by-name"
或您为验证添加的任何默认类。