2017-04-12 128 views
-1

下面的代碼本身在輸入表單中的值刪除與單選按鈕

<Input type = "radio"> <Input type = "text" name = "nominal" value = "1000"> 

我想用單選按鈕刪除輸入形式的價值,怎麼樣?

請幫我

感謝

+0

復位一樣的形式? – Swellar

+0

是的,真的很喜歡 你能幫我嗎? –

+0

爲什麼你有一個單選按鈕?他們應該用於小組。 – nnnnnn

回答

0

下面是一個例子代碼

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> 

    <script type="text/javascript"> 
     $(document).ready(function(){ 
     $('#radio').change(function(){ 
      $('#nominal').val(''); 
     }); 
     }); 
    </script> 

    <div> 
     <input id="radio" type= "radio"> 
     <input id="nominal" type= "text" name="nominal" value="1000"> 
    </div> 
+0

太好了,謝謝大師 –

+0

歡迎您! –

+0

但是取消後再次填充的內容呢? –

0

你可以這樣做以下(無jQuery):

var isChecked = true; 
 
function handleClick(e) { 
 
    if(isChecked){ 
 
    document.getElementById('txtNominal').value = ''; 
 
    document.getElementById('myRadio').checked = true; 
 
    isChecked = false; 
 
    } 
 
    else{ 
 
    document.getElementById('txtNominal').value = '1000'; 
 
    document.getElementById('myRadio').checked = false; 
 
    isChecked = true; 
 
    } 
 
}
<input type = "radio" id="myRadio" onclick="handleClick(event);" /> 
 
<input type = "text" id="txtNominal" name = "nominal" value = "1000">

+0

很少更改,但取消後再次選中填充? –

+0

您是否想要取消選中的值? – Mamun

+0

是的,正確的,主人怎麼樣? –

0

解決方案使用複選框

<script type="text/javascript"> 
    $(document).ready(function(){ 

     $('#checkbox').change(function() { 
       if($('#checkbox').is(':checked')) { 
        $('#nominal').val(''); 
       } else { 
        $('#nominal').val(1000);  
       } 
     }); 
    }); 
</script> 

<div> 
    <input id="checkbox" type= "checkbox"> 
    <input id="nominal" type= "text" name="nominal" value="1000"> 
</div> 
+0

如何取消選中返回值,而不是確定的值? 不是這樣的:$('#nominal')。 Val(1000); –

+0

那麼你想要取代什麼價值? –