0

这又是我使用但没有 css 的完整代码,我只想运行这 2 个 javascript,任何人都可以将编辑的完整代码发送给我吗?

这是我的演示页面http://iscree.orgfree.com

在这里我有 jquery-1.4.2.js 但是当它们在指定页面中时它适用于两个代码,而不是同一页面!

<script type="text/javascript" src="http://www.iscreen.orgfree.com/js/jquery-1.4.2.js"></script>
<style type="text/css">a {text-decoration: none}</style>


<!Here is js1---------->
<script type="text/javascript">//<![CDATA[ 
$(window).load(function(){
jQuery(document).ready(function(){
    jQuery('#hideshow').live('click', function(event) {        
         jQuery('#content').toggle('show');
    });
});
});//]]>  
</script>
<!Here is js1---------->

<!Here is js2---------->
<script type='text/javascript'>//<![CDATA[ 
$(windows).load(function(){
              // Optional code to hide all divs
            $("div").hide();
              // Show chosen div, and hide all others
            $("input").click(function () 
            {
                $("#" + $(this).attr("class")).show().siblings('div').hide();
            });

});//]]>  
</script>
<!Here is js2---------->



<!Here example1---------->
  Click a button to make it visible:<br /><br />
<input type="button" value="One" class="one" />
<input type="button" value="Two" class="two" />
<input type="button" value="Three" class="three" />
<input type="button" value="Four" class="four" /><br /><br />

        <div id="one">One</div>
        <div id="two">Two</div>
        <div id="three">Three</div>
        <div id="four">Four</div><br/><br/>
<!Here example1---------->



<!Here example2---------->
<a href="#" id='hideshow'>here</a>


<div id='content' class="content" style="display: none;">

<div id="container" style="width:300px">
<div id="title" style="background-color:#161616;">
<center><h1 style="margin-bottom: 0; color: white;">iScreen Desktop</h1></center>
</div>

<div id="row1left" style="background-color:#636262;height: 150px;width:150px;float:left;">
<center><a href="#" class="topopup">Some text</a></center>
</div>

<div id="row1right" style="background-color:#161616;color: white;height: 150px;width:150px;float:left;">
<p>Content goes here</p>
</div>

<div id="row2left" style="background-color:#636262;height: 60px;width:150px;float:left;">
<center><form name="tokey"><input type="text" name="key" onblur="if (this.value == '') {this.value = 'Kerko';}" onfocus="if(this.value == 'Kerko') {this.value = '';}" value="Kerko" size="10"><input type="button" onClick="ToKey()" value="Go"></form></center>
</div>

<div id="row2right" style="background-color:#161616;color: white;height: 55px;width:150px;float:left;">
<center><a href="logout.php"><img src="./users/desktop/img/shdown.png" height="19" width="19"> <font size="5" style="color: white">Shkyqu</font></a></center>
</div>

<div id="footer" style="background-color:#161616;color: white;clear:both;text-align:center;">
By SMKproduction.eu5.org</div>
</div>
</div>


<!Here example2---------->
4

2 回答 2

0

为什么不将所有代码放在同一个“就绪”调用中?:

<script type="text/javascript">

    $(document).ready(function(){
         $('#hideshow').live('click', function(event) {        
              $('#content').toggle('show');
         });

         $("div").hide();
         // Show chosen div, and hide all others
         $("input").click(function () 
         {
            $("#" + $(this).attr("class")).show().siblings('div').hide();
         });
    });
</script> 

注意 window.load 和 jQuery.ready 具有相同的目的:在浏览器完成加载文档时执行函数。你不需要他们两个...

于 2013-08-28T10:43:38.990 回答
0

只需将它们放入 document.ready

    $(document).ready(function () {
        jQuery('#hideshow').live('click', function (event) {
                jQuery('#content').toggle('show');
        });

        $("div").hide();

        $("input").click(function () {
                $("#" + $(this).attr("class")).show().siblings('div').hide();
        });
});
于 2013-08-28T10:47:12.603 回答