开发者

jQuery: Any better way to write this? Muliple calls to the same function with parameters

function bookingResults(){
  checkAllRadios("#acknowledgeAll", ".acknowledgeThis");
 开发者_StackOverflow社区 checkAllRadios("#confirmAll", ".confirmThis");
  checkAllRadios("#rejectAll", ".rejectThis");
}

When the id is clicked, check all the elements with the class name.


We don't know how your function works. But you can do:

$('.acknowledgeThis, .confirmThis, .rejectThis').attr('checked', 'checked');


Regarding $('.acknowledgeThis, .confirmThis, .rejectThis').attr('checked', 'checked'); , that's the old way to do it in jQuery. But if you're using any version 1.6 or higher, the correct way to do it now is this:

$('.acknowledgeThis, .confirmThis, .rejectThis').prop('checked', true);

The attr() setter version has been deprecated since 1.6, and might be removed in a future version.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜