不知道JQuery有什么简单的办法完成下列功能?var str = "str1,str2,str3,str4";
var txt = "hello world";现在把txt显示在一个DIV里,希望达到的效果是:
1. 当用户点击txt的时候(单击hello world),悬浮出现str的内容(str1,str2,str3,str4);点击别处,悬浮框消失。
2. 当用户点击悬浮框某一个字段的时候,替换掉txt的显示内容 (比如点击str2,则在DIV只显示str2,替换掉hello world)
谢谢!

解决方案 »

  1.   

    刚给别人做的,你参考一下吧!<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>无标题页</title>
        <style type="text/css">
            #choice table{ border:3px double red; border-collapse:collapse; width:100%; }
            #choice td { border: 1px solid gray; padding:10px; }
            #choice{ display:none; border:1px solid blue; width:500px; height:200px; text-align:center; padding:20px; }
            
        </style>
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
        <script type="text/javascript">
            $(function(){
                $("#btnDiv").click(function(){
                   $('#choice').html('<table><tr><td>12345</td></tr><tr><td>ABCDEFG</td></tr></table>').show('slow');
                   $("#choice td").click(function(){
                       $('#display').val($(this).html());
                       $('#choice').hide('slow');
                   });
                });
            });
        </script>
    </head>
    <body>
    <input type="text" id='display' />
    <input type="button" id="btnDiv" value="显示div" />
    <div id='choice'></div>
    </body>
    </html>
      

  2.   

    这里有一个满足你的要求
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
        <head> 
            <meta http-equiv="Content-Type" content="text/html; charset=GB2312" /> 
            <title>点击一个连接显示层~点击其他区域隐藏 练习 by 脚本之家</title> 
            <style type="text/css"> 
                #myDiv{ 
                    border:1px solid #000000; 
                    width:200px; 
                    height:100px; 
                    background:#cccccc; 
                } 
            </style> 
            <script language="JavaScript" type="text/javascript"> 
            function addListener(element,e,fn){ 
           if(element.addEventListener){ 
           element.addEventListener(e,fn,false); 
           } else { 
            element.attachEvent("on" + e,fn); 
           } 
         } 
            addListener(document,"click",function(evt){ 
                    var evt = window.event?window.event:evt,target=evt.srcElement||evt.target; 
                    if(target.id == "showDiv"){ 
                        document.getElementById("myDiv").style.display = ""; 
                        return; 
                    }else{ 
                        while(target.nodeName.toLowerCase() != "div" && target.nodeName.toLowerCase() != "html"){ 
                            target = target.parentNode;         
                        } 
                        if(target.nodeName.toLowerCase() == "html"){ 
                            document.getElementById("myDiv").style.display = "none"; 
                        } 
                             
                         
                    }             
            }) 
            </script> 
        </head> 
        <body> 
            <div id="myDiv" style="display:none;">Hello World</div> 
            <input type="button" value="出来吧层" id="showDiv" /> 
        </body> 
    </html>其他的不明白你的意思,var str = "str1,str2,str3,str4";你可以把str1这些又放在一个div里然后完成你的需求
      

  3.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.js"></script>
        <script type="text/javascript">
            $(function () {
                var str = "str1,str2,str3,str4";
                var txt = "hello world";
                $('#container').html(txt).click(function () {
                    $('#showContainer').show('slow');
                });
                $.each(str.split(','), function (i, n) {
                    $('#showContainer').append($('<span> ' + n + ' </span>').click(function () {
                        $('#container').html($(this).html());
                    }));
                });            $(document).click(function () {
                    $('#showContainer').hide();
                });        });
        </script>
    </head>
    <body><div id="container" style="border:1px solid green;"></div>
    <div id="showContainer" style="display:none;border:1px solid red"></div>
    </body>
    </html>