比如我给TextBox(ID为txtA)加了个事件: txtA.Attributes.Add("onclick", "javascript:return show()");
然后在弹出的div里面选择一个东西,填到txtA里面,现在问题是怎么让弹出的这个DIV关闭(隐藏起来)?如果是在body里面写,又会和txtA冲突,不弹出了。
<body onclick="close();"></body>  这样就不弹出了,到底怎么办才好?

解决方案 »

  1.   

    不用CLICK事件。用 onfocus(获得焦点) 打开层。onblur(离开焦点) 隐藏层。
      

  2.   

    ie下用cancelBubble ff下用stopPropagation阻止事件传递
    例子<SCRIPT>   
    function show(){
    event.cancelBubble = true;
    document.getElementById("pad").style.display = "block";
    return false;
    }
    function doClose(){
    document.getElementById("pad").style.display = "none";
    }
    </SCRIPT>
    <body onclick="doClose();">
    <input type="text" name="txtA" value="click" onclick="show();">
    <div id="pad" style="display:none;position:absolute;left:300px;top:300px;width:300px;height:300px;background:red;">xxxx</div>
    </body>
      

  3.   


    <SCRIPT>   
    function show(evt){
    if(window.event) event.cancelBubble = true;
    else evt.stopPropagation();
    document.getElementById("pad").style.display = "block";
    return false;
    }
    function doClose(){
    document.getElementById("pad").style.display = "none";
    }
    </SCRIPT>
    <body onclick="doClose();">
    <input type="text" name="txtA" value="click" onclick="show(event);">
    <div id="pad" style="display:none;position:absolute;left:300px;top:300px;width:300px;height:300px;background:red;">xxxx</div>
    </body>
      

  4.   

    就把这个div隐藏掉就可以了。
      

  5.   

    对这个event.cancelBubble有所了解了.