求一段javascript代码,可以用户点选checkbox以后在下面生成一个输入文本的框

然后反选的时候文本框消失万分感谢!!
2025-02-02 07:50:05
推荐回答(3个)
回答1:





    
    
            function $(id){
               return  document.getElementById(id);
            }

        window.onload = function () {
            var test = $("test");
            test.onclick = function(){
                if(this.checked){
                    $("input").style.display = "block";
                }else{
                    $("input").style.display = "none";
                }
            }
        }
    
    
        .main{
            width: 400px;
            height:300px;
            border: 1px solid #ddd;
            margin:auto;
        }
    


    
        
        


    


回答2:

checkbox绑定点击事件,

在checkbox后面放一个

上面是让他先隐藏....

然后写jquery事件

 function click( )
 {
    if($("#checkbox").attr("checked")=="checked")//如果被选中了,就显示输入框
    {
       $("#text1").show();
    }
    else
    {
       $("#text1").hide();
    }
 }

回答3: