2 回答

TA貢獻1808條經驗 獲得超4個贊
<input type="text" id="txtName" />
<input type="checkbox" name="cbInput" value="1" onclick="fChange()" />
<input type="checkbox" name="cbInput" value="2" onclick="fChange()" />
<input type="checkbox" name="cbInput" value="3" onclick="fChange()" />
<script type="text/javascript">
function fChange(){
??? var objs = document.getElementsByName("cbInput");
??? var objValue="";
??? for(var i=0; i<objs.length; i++){
??????? if(objs[i].type=="checkbox" ){
??????????? if(objs[i].checked){
??????????????? objValue=objValue+","+objs[i].value;
??????????? }
??????? }
??? }
??? if(objValue.length>0){
??????? objValue=objValue.substr(1,objValue.length-1);
??? }
??? document.getElementById("txtName").value=objValue;
}
</script>
- 2 回答
- 0 關注
- 483 瀏覽
添加回答
舉報