我的页面上有一个jQuery click函数,它会触发打开一个反馈表单div。基本上,我想指定一个将触发此事件的URL,而无需单击它。如foo.com?formopen
这可能吗?我在想我需要通过url传递一些数据,但不确定如何处理。
最佳答案
在网址中使用哈希,例如:
foo.com#formopen
然后在加载时找到该哈希,例如:
$(function(){
if (window.location.hash){
var hash = window.location.hash.substring(1);
if (hash == "formopen"){
openFeedbackForm();
}
}
});
演示:
代码:http://jsfiddle.net/J5cxc/
无哈希演示:http://fiddle.jshell.net/J5cxc/show(无警报)
带有哈希的演示:http://fiddle.jshell.net/J5cxc/show/#foobar(警告)
关于jquery - 使用url参数触发jQuery click事件吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13492850/