2013-05-27 58 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'); } }; ' 感谢您的所有回应。 –