2011-04-22 62 views
1

這是我單選按鈕將禁用選擇(「其他」不工作)

<script type="text/javascript"> 

    $('input:radio[name="RADIOSELECTOR"]').change(function() { 

     if ($(this).val()=='one') { 
       $('#ones').removeAttr('disabled'); 
      $('#twos').attr('disabled',true); 
     } else if ($(this).val()=='two') { 
      $('#ones').attr('disabled',true); 
      $('#twos').removeAttr('disabled'); 
     } else { 
      $('#ones').attr('disabled',true); 
        $('#twos').attr('disabled',true); 
     } 


        }); 
</script> 

<form name="order" action="managecart.html" onsubmit="return AddToCart(this); return ValidateCart(this);"> 
<input name="PRICE" type=hidden id="PRICE" value="" /> 
<input name=NAME type=hidden id="NAME" value="" /> 
<input name=ID_NUM type=hidden id="ID_NUM" value="" /> 
<input type=hidden name="SHIPPING" value="0.00" /> 
<input type="radio" name="RADIOSELECTOR" value="lose" onClick="document.order.PRICE.value='59.99'; document.order.NAME.value='iPhone 3G Glass/digitiazer replacement'; document.order.ID_NUM.value='3GGL'; document.order.SHIPPING.value='0.00';" />Glass/digitizer repair <b>59.99$</b><br><br> 
<b> Combo repairs:</b><BR><br> 
<input type="radio" name="RADIOSELECTOR" value="lose" onClick="document.order.PRICE.value='74.99'; document.order.NAME.value='iPhone 3G Glass/digitizer + battery repair'; document.order.ID_NUM.value='3GGLB'; document.order.SHIPPING.value='0.00';" />Glass/digitizer + battery repair = <b> 74.99$</b> 25$ in savings!<br> 

<input type="radio" name="RADIOSELECTOR" value="one" onClick="document.order.PRICE.value='79.99'; document.order.NAME.value='iPhone 3G Glass/digitizer + combo '; document.order.ID_NUM.value='3GGLC'; document.order.SHIPPING.value='0.00';" />Glass/digitizer + <select id="ones" name="ADDITIONALINFO2" disabled="disabled"> 
<option value=" "></option><option value="Home button">Home button</option> <option value="Power button">Power button</option><option value="Mute switch">Mute switch</option><option value="volume button">Volume button</option></select> 

= <b>79.99$</b> 30$ in savings!<br> 

<input type="radio" name="RADIOSELECTOR" value="two" onClick="document.order.PRICE.value='99.99'; document.order.NAME.value='iPhone 3G Glass/digitizer + combo + ''ADDITIONALINFO3'; document.order.ID_NUM.value='3GGLBC'; document.order.SHIPPING.value='0.00';" />Glass/digitizer + battery + <select name="ADDITIONALINFO3" id="twos" disabled="disabled"><option value=" "></option><option value="Home button">Home button</option> <option value="Power button">Power button</option><option value="Mute switch">Mute switch</option><option value="volume button">Volume button</option></select> = <b>99.99$</b> 30$ in savings!<br> 

<input name="QUANTITY" type="hidden" value="1" /><br> 
<input type="image" src="./images/addtocart.png" align="center" name="BUY" value=" Add to cart " ALT="Add to Cart"> 
</form> 

DEMO http://jsfiddle.net/uSmVD/86/

腳本不會在HTML文件中工作。如何解決這個問題? 這裏是實際的頁面即時試圖讓這個工作http://icuretech.com/revision/iphone-3g-glass-repair.html

+0

你可以用適當的縮進格式化你的代碼,使其清晰? – 2011-04-22 03:02:44

+0

http://jsfiddle.net/uSmVD/79/這就是發生什麼 – Rafal 2011-04-22 03:24:47

+0

因爲中間塊應該使用'else if',而不是'if'。給[this](http://homepage.ntlworld.com/kayseycarvey/controlflow3.html)一讀。 – 2011-04-22 03:31:53

回答

0

你沒有一個輸入的值是lose1。您有lose1單獨作爲某些輸入的值,但不是兩者,因此表達式永遠不會根據您的要求進行評估。

+0

真的,我沒有糾正,但當我做別人{$('#ones')。attr('disabled',true); $('#twos')。attr('disabled',true); } 我無法正常工作,爲什麼?另外,當我把腳本放在HTML正文中不起作用時,謝謝你的回覆 – Rafal 2011-04-22 03:20:23

+0

好吧,對於初學者來說,你將刪除一個名爲「禁用」的屬性,而這個屬性你並沒有首先分配。因此,如果您在其他任何語句之前觸擊了其他語句,則無法從一開始就刪除不存在的屬性。另外,我甚至在代碼中提供的腳本片段中看不到其他語句。最後,如果你想將它嵌入到body中,你需要確保你的Javascript包裝在一個

0
<script src="prototype.js"></script> 
<script src="jquery.js"></script> 

    <script> 
    $('input:radio[name="RADIOSELECTOR"]').change(function() { 

     if ($(this).val()=='one') { 
       $('#ones').removeAttr('disabled'); 
      $('#twos').attr('disabled',true); 
     } if ($(this).val()=='two') { 
      $('#ones').attr('disabled',true); 
      $('#twos').removeAttr('disabled'); 
     } if ($(this).val()=='lose') { 
      $('#ones').attr('disabled',true); 
        $('#twos').attr('disabled',true); 
     } 
      if ($(this).val()=='lose1') { 
      $('#ones').attr('disabled',true); 
        $('#twos').attr('disabled',true); 
     } 

    }); 

    </script> 
<form name="order" action="managecart.html" onsubmit="return AddToCart(this); return ValidateCart(this);"> 
<input name="PRICE" type=hidden id="PRICE" value="" /> 
<input name=NAME type=hidden id="NAME" value="" /> 
<input name=ID_NUM type=hidden id="ID_NUM" value="" /> 
<input type=hidden name="SHIPPING" value="0.00" /> 
<input type="radio" name="RADIOSELECTOR" value="lose" onClick="document.order.PRICE.value='59.99'; document.order.NAME.value='iPhone 3G Glass/digitiazer replacement'; document.order.ID_NUM.value='3GGL'; document.order.SHIPPING.value='0.00';" />Glass/digitizer repair <b>59.99$</b><br><br> 
<b> Combo repairs:</b><BR><br> 
<input type="radio" name="RADIOSELECTOR" value="lose" onClick="document.order.PRICE.value='74.99'; document.order.NAME.value='iPhone 3G Glass/digitizer + battery repair'; document.order.ID_NUM.value='3GGLB'; document.order.SHIPPING.value='0.00';" />Glass/digitizer + battery repair = <b> 74.99$</b> 25$ in savings!<br> 

<input type="radio" name="RADIOSELECTOR" value="one" onClick="document.order.PRICE.value='79.99'; document.order.NAME.value='iPhone 3G Glass/digitizer + combo '; document.order.ID_NUM.value='3GGLC'; document.order.SHIPPING.value='0.00';" />Glass/digitizer + <select id="ones" name="ADDITIONALINFO2"> 
<option value=" "></option><option value="Home button">Home button</option> <option value="Power button">Power button</option><option value="Mute switch">Mute switch</option><option value="volume button">Volume button</option></select> 

= <b>79.99$</b> 30$ in savings!<br> 

<input type="radio" name="RADIOSELECTOR" value="two" onClick="document.order.PRICE.value='99.99'; document.order.NAME.value='iPhone 3G Glass/digitizer + combo + ''ADDITIONALINFO3'; document.order.ID_NUM.value='3GGLBC'; document.order.SHIPPING.value='0.00';" />Glass/digitizer + battery + <select name="ADDITIONALINFO3" id="twos" ><option value=" "></option><option value="Home button">Home button</option> <option value="Power button">Power button</option><option value="Mute switch">Mute switch</option><option value="volume button">Volume button</option></select> = <b>99.99$</b> 30$ in savings!<br> 

<input name="QUANTITY" type="hidden" value="1" /><br> 
<input type="image" src="./images/addtocart.png" align="center" name="BUY" value=" Add to cart " ALT="Add to Cart"> 
</form> 
+1

它不工作:/ – Rafal 2011-04-23 01:49:51

相關問題