2010-08-21 37 views
0

正常JS函數內部:jGrowl:有一個id裏面的函數,不會工作,只有在沒有id的情況下才行?

$('#friendsPop').jGrowl("testtmee"); 

不會工作,但是:

$.jGrowl("testmeee"); 

作品就好了..我已經測試過的一切,如果我做一個函數以外的連結,正常的一個:像這樣的鏈接:

<a href="javascript:void(0);" onclick="$('#friendsPop').jGrowl('testme');">link</a> 

它也可以正常工作。但我想激活

$('#friendsPop').jGrowl("testtmee"); 

ajax成功後,我需要一個ID。

我該怎麼辦?

回答

0

我已經不時地使用jGrowl,並且我不記得曾經在一組選定的jQuery對象上調用它。 jGrowl的重點在於,它在窗口級別生成「獨立」消息 - 一條單一的全局消息流,而不管它們是如何被調用的(或來自哪裏)。就像它所基於的Mac OS X Growl概念一樣。

檢查jGrowl documentation,我也看不出這就是所謂的任何像這樣的例子:

$('.something').jGrowl('message'); 
// what would this even mean in jGrowl terms? 

它總是這樣的:

$.jGrowl('message'); 

如果它的工作對你偶爾這樣,這是偶然的偶然事件(我沒有看過jGrowl源代碼來找出原因,但我確定答案在那裏)。

只要叫它$.jGrowl('Like This'),你就全都定了。

+0

嗨,肯。我需要指定一個#id,所以在我的另一個Ajax調用成功,我可以做$('#something')。jGrowl('close'); ..這就是爲什麼我希望它工作並不總是這樣,如果例如下載jgrowl,在例子dirr的jquery.html中,你會發現自定義容器$('#test1')。jGrowl('message');等等,然後在身體關閉之前,你會發現

,所以它顯示在特定的位置(左下角的例子)。 – Karem 2010-08-22 10:04:26

+0

Karem,你能設置一個顯示問題的可訪問頁面嗎? – 2010-08-22 15:34:36

1

你要添加到您的Ajax請求:

var mesScripts = document.getElementById("mapleft").getElementsByTagName("script"); 
for (var i=0; i<mesScripts.length; i++) { 
    eval(mesScripts[i].innerHTML); 

它改革<script> AJAX加載後。

1

這是我的建議。由於無法將jGrowl相對於DIV進行放置,無論是向左還是向右移動,我們都會在渲染後將其轉移。以下是我從原始示例中獲取的代碼。

(function($){ 
    $.jGrowl.defaults.pool = 5; 
    $.jGrowl.defaults.sticky = true; 
    $.jGrowl.defaults.life = 2500; 
    $.jGrowl.defaults.closer = true; 
    $.jGrowl.defaults.open = function(e,m,o) {$("#jGrowl").css('right', $('#header').offset().left + 17);}; 

    /** 
    * @todo Add the twitter avatars to tweets, via tweet.user["profile_image_url"] 
    * @todo Find a way to calculate the dates relatively 
    * @todo Test is a cookie plugin is available so that some of this data can be 'cached' 
    */ 
    $.jTweet = function(username , total) { 
     $.getJSON("http://twitter.com/status/user_timeline/" + username + ".json?count=" + total + "&callback=?", function(response) { 
      $.each(response, function(i, tweet) { 
       $.jGrowl((tweet.text.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) { 
        return m.link(m); 
       })) + ' [' + tweet.source + ']' , { 
        header: tweet.created_at , 
        }); 
      }); 
     }); 
    }; 

    $.jTweet('jquery', 5); 
})(jQuery); 

這裏最重要的部分是線:

$.jGrowl.defaults.open = function(e,m,o) {$("#jGrowl").css('right', $('#header').offset().left + 17);}; 

哪個jGrowl對象的右鍵屬性對齊到我的標題左側財產。這基本上轉移它的位置,使它看起來好像它在標題的div。

相關問題