2014-11-06 43 views
0

我有一個表單,如果值是一件事,那麼出現在.help塊中的文本應該相應地改變。這裏是表格:http://lakenney.github.io/contact.html選中'我想要自定義的東西'和單選按鈕下拉框。點擊第一個施華洛世奇項鍊單選按鈕,相應的文字'施華洛世奇水晶閃耀'出現在.help塊中。但其他單選按鈕不起作用。jQuery輸入:無線​​電改變幫助塊中的val文本

我有一個與選擇元件工作的例子:http://lakenney.github.io/form-start-video2.html ......看到「請選擇一個」和相應的文本填充。幫助塊

任何幫助,將不勝感激。

+0

請張貼代碼。 – 2014-11-06 03:34:44

回答

0

修改JavaScript到這個代替:

$('input:radio').change(function(){ 

     if ($(this).val() == 'swarovski') { 
      $('.request-custom .help-block').text('Swarovski crystals sparkle'); 
     } else if ($(this).val() == 'mirano') { 
      $('.request-custom .help-block').text('Mirano crystals sparkle'); 
     } else if ($(this).val() == 'locket') { 
      $('.request-custom .help-block').text('Lockets are awesome!'); 
     } else if ($(this).val() == 'soldering') { 
      $('.request-custom .help-block').text('Soldering Rock!'); 
     } else { 
      $('.request-custom .help-block').text(''); 
     } 

}); 

基本上,使用

$(本).VAL()

捕捉值。您正在用

$( '輸入:無線​​電')。VAL()

這將導致總是返回第一個$( '輸入:無線​​電'),這恰好是施華洛世奇。