2013-05-27 66 views
0

我試圖結合兩個JQuery函數,但沒有任何成功。結合2個不同的jQuery函數

if (querySt("photoid")) { 
    var value = querySt("photoid"); 
    alert(value); 
} 

window.onload = function() { 
    if(window.location.hash) { 
    $(window.location.hash).trigger('click'); 
    } 
}; 

曾嘗試以下:

if (querySt("photoid")) { 
    var value = querySt("photoid"); 
    window.onload = function() { 
    if(window.location.value) { 
     $('#' + window.location.value).trigger('click'); 
    } 
    } 
}; 

哈希需要與實際的 '#' 符號來代替。 photoid返回像415的圖像id值。

任何建議將不勝感激。

親切的問候, 查爾

回答

1

你應該試試這個

window.onload = function() { 

    if (querySt("photoid")) { 
     var value = querySt("photoid"); 
     alert(value); 
    } 

    if(window.location.hash) { 
     $(window.location.hash).trigger('click'); 
    } 

}; 
+2

注意,使用jQuery的時候,它通常最好使用'的(),而不是'窗口jQuery的'$(文件)。就緒。 onload'。 –

+0

感謝您的答覆... 還需要到 'VAR值結合起來= querySt( 「PHOTOID」);'和'$(window.location.hash).trigger( '點擊');' 嘗試'$('#'+ window.location.value).trigger('click');' 因此,將使用photoid來代替window.location.hash,並調用window.location.photoid。 問候, 查爾 –

+0

通過使用以下解決該問題: '\t的window.onload =函數(){ 如果(querySt( 「PHOTOID」)){ VAR值= querySt( 「PHOTOID」); \t \t window.location.hash = querySt(「photoid」); } if(window.location.hash){(window.location.hash).trigger('click'); } }; ' 感謝您的所有迴應。 –