English 中文(简体)
代码在控制台工作, 但不是在头部工作
原标题:Code works in console, but not in head
  • 时间:2012-05-23 10:33:02
  •  标签:
  • jquery

当我在谷歌铬控制台输入此脚本时...

<script>
    $(document).ready(function() {  
        $("div").hover(
            function() { $("> span", this).show(); },
            function() { $("> span", this).hide(); 
        });
    });
</script>

...它的工作,没有问题。

当我在 之间添加此点时, 它不起作用 。

有人能告诉我为什么吗?

<强> UPDATE

<script type="text/javascript">!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
     <script type="text/javascript" lang="javascript">
    $(document).ready(function()
{
    $( div ).hover(function()
    {
        $( > span , this).show();
    }, function()
    {
        $( > span , this).hide();
    });
});
    </script>
    <script type="text/javascript" lang="javascript">

    $.getJSON("http://twitter.com/statuses/user_timeline/username.json?callback=?&count=5", function(data) {

  $.each(data, function(index, value) { 
 $( .tweets ).append( <div id= +data[index].id+ > +data[index].text+ &nbsp<span style="display:none"class="hideTweeterIcons"><a href="https://twitter.com/intent/tweet?in_reply_to= +data[index].id+ "><img src="//si0.twimg.com/images/dev/cms/intents/icons/reply.png"></a><a href="https://twitter.com/intent/retweet?tweet_id= +data[index].id+ "><img src="//si0.twimg.com/images/dev/cms/intents/icons/retweet.png"></a><a href="https://twitter.com/intent/favorite?tweet_id= +data[index].id+ "><img src="https://si0.twimg.com/images/dev/cms/intents/icons/favorite.png"></a></span></div><hr> );

});     
});

    </script>
问题回答

您提供的代码是 < a href=" "http://jquery.com/" rel="nofollow" >jQuery 库 , 请确定您在使用 jQuery $ 函数之前包含对图书馆的引用。 此外, 请尝试在脚本标签上指定 type , 如 :

<script type="text/javascript">
    ...
</script>

Update

修改您的代码后, 我注意到 hover 功能设置错误, 请尝试 :

$(document).ready(function()
{
    $( div ).hover(function()
    {
        $( > span , this).show();
    }, function()
    {
        $( > span , this).hide();
    });
});

您需要确定 jQuery 代码是否在您添加到 jQuery 库之后。 如果您正在使用 HTML5 锅炉板, 则会在页面底部发生 。





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...