我在產品視圖自定義選項中添加了兩個單選按鈕。和一個依賴於單選按鈕的文本輸入欄。所以當第一個廣播是檢查第一個文本是隱藏的,我添加這個字符:「-------」輸入文本的值屬性。當第二個單選按鈕被選中時,我需要顯示文本輸入字段並刪除值「-------」。Magento自定義選項 - 清除輸入字段問題
要將值添加到文字輸入使用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', '');
}
})
所以我想要的是當第一個廣播被檢查並且輸入文本字段被隱藏以通過驗證並且當第二個廣播被檢查並且文本輸入字段被顯示時移除該值時將該默認值添加到文本輸入字段。
謝謝
變化'.attr( '值', '--------');'在你的第二個變化事件的人 – madalinivascu
謝謝madalin ivascu,但我不很瞭解 – Robert
你不明白什麼? – madalinivascu