用url参数触发jQuery click事件?

caf*_*igh 1 jquery

我的页面上有一个jQuery点击功能,触发了反馈表单div的打开.基本上我想指定一个触发此事件的URL,而不需要点击它.比如foo.com?formopen

这可能吗?我想我需要通过网址传递一些数据,但不知道如何去做.

Cur*_*urt 9

在您的网址中使用哈希,例如:

foo.com#formopen
Run Code Online (Sandbox Code Playgroud)

然后在加载时找到哈希像:

$(function(){

   if (window.location.hash){
      var hash = window.location.hash.substring(1);
      if (hash == "formopen"){
         openFeedbackForm();
      }
   }

});
Run Code Online (Sandbox Code Playgroud)

DEMO:

代码:http://jsfiddle.net/J5cxc/

没有哈希的演示:http://fiddle.jshell.net/J5cxc/show(无警报)

用Hash演示:http://fiddle.jshell.net/J5cxc/show/#foobar(提醒叫)