2010-10-20 156 views

回答

1
<input type="checkbox" name="foo" onclick="document.getElementById('idtextfield').value = +this.checked;" /> 
1

你可以這樣做:

var chk = document.getElementById('checkbox_id'); 
    var txt = document.getElementById('textbox_id'); 

    chk.onclick = function(){ 
    if (this.checked === true){ 
     txt.value = '1'; 
    } 
    else{ 
     txt.value = '0'; 
    } 
    }; 
0
window.onload = function() { 
    var checkBox = document.getElementById('idofcheck'); 
    if (checkBox == null) { 
     return; 
    } 

    checkBox.onclick = function() { 
     var textField = document.getElementByd('ifoftextfield'); 
     if (textField == null) { 
      return; 
     } 

     if (this.checked) { 
      textField.value = '1';  
     } else { 
      textField.value = '0'; 
     } 
    }; 
}; 
0
if(document.getElementById("checkbox1").checked) 
    { 
    document.getElementById('textbox1').value=1; 
    } 

    else 
    { 
    document.getElementById('textbox1').value=''; 
    } 
相關問題