0

I have function on jQuery who by onclick event send post request and change value in table row.

How i can do it mass? For example, i have button "Check all" on click this, i call function. I want to click-once summoned all the check and then they started to be executed

pseudo code:

<ul>
  <li id=1>text1</li>
  <li id=2>text2</li>
  <li id=3>text3</li>
</ul>

<button id="checkall">check all</button>
<script>

function check(id) { /* ... */ }'

on('click', '#checkall', {
  $("ul li").each(function() { 
    check(this.attr('id'));
  });
});

</script>

Yes, i know thats its stupid idea, but, how i can do it? ^_^

Thanks.

4

2 回答 2

1

你应该这样做:

var check = function() { ... };

$('#checkall').on('click',function() {
  $("ul li").each(function() { 
    check(this);//to check it all use your function
    //other code
  });
});

我使用this是因为我不知道正在调用哪个函数以及传递给什么变量。

于 2013-06-19T22:01:35.537 回答
0

下面的代码将触发li的点击事件(你说你已经设置)

on('click', '#checkall', {
  $("ul li").trigger('click');
});

您应该注意到您可以同时运行的ajax有限制,请查看以下流行浏览器允许多少并发AJAX(XmlHttpRequest)请求?

如果您需要在触发点击之前运行某些功能,您可以执行以下操作:

$("ul li").each(function() { 
    // Your code here
    $(this).trigger('click');
  });

总而言之,我认为你走错了路。

于 2013-06-19T22:21:29.930 回答