Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用带有参数的jquery:nth-child()选择器_Jquery - Fatal编程技术网

使用带有参数的jquery:nth-child()选择器

使用带有参数的jquery:nth-child()选择器,jquery,Jquery,是否可以将jquery选择器:n子级与参数一起使用 var ok = function(a) { $("#divid:nth-child(a)").click(function() { ............. }); }; $(function() { $("#divId2").click(ok(4)); }); 谢谢你的帮助 当然可以,只需执行$'divid:nth child'+a+.blabla即可 哦,请确保a实际上是一个数

是否可以将jquery选择器:n子级与参数一起使用

var ok = function(a)
{ 
    $("#divid:nth-child(a)").click(function()
    {
           .............
    });
};

$(function()
{
    $("#divId2").click(ok(4));
});
谢谢你的帮助

当然可以,只需执行$'divid:nth child'+a+.blabla即可


哦,请确保a实际上是一个数字,否则您可能会得到意外的结果/错误。

在键入问题时,您应该花更多的时间。是否确实要在单击事件中定义单击事件?为什么要执行$divid:n子项。。。?页面上是否有多个ID相同的元素?这个$divId2.clickok4;除非ok函数返回处理程序,否则没有意义。