将变量发送到JQuery函数

Jes*_*ler 3 jquery

我是jQuery的新手,但我希望有人能够帮助我.我搜索了这个论坛(和其他人),但一直找不到我能做的答案.

我有这样的链接:

<a href="#">
Run Code Online (Sandbox Code Playgroud)

和一个jQuery脚本:

$("div.show_dialogbox").click(function(){
    $("div#dialogboxwraper").animate({
        height: "400px"
    }, "slow")
    .animate({
        height: "200px"
    }, "slow");
});
Run Code Online (Sandbox Code Playgroud)

我希望能够发送一个带有链接的变量,并在脚本中使用它,如下所示:

<a href="#" OnClick="variable(200)">


$("div.show_dialogbox").click(function(variable){
    $("div#dialogboxwraper").animate({
        height: variable+200+"px"
    }, "slow")
    .animate({
        height: variable+"px"
    }, "slow");
});
Run Code Online (Sandbox Code Playgroud)

Nic*_*ver 7

我会在这里使用数据属性,在jQuery 1.4.3中添加了更多支持,如下所示:

<a href="#" class="show_dialogbox" data-height="200">
Run Code Online (Sandbox Code Playgroud)

然后在jQuery中:

$("a.show_dialogbox").click(function(){
  $("#dialogboxwraper").animate({
    height: $(this).data('height') + 200
  }, "slow")
  .animate({
    height: $(this).data('height')
  }, "slow");
});
Run Code Online (Sandbox Code Playgroud)

你可以在这里测试一下.