开发者

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

开发者 https://www.devze.com 2023-03-03 00:27 出处:网络
function bookingResults(){ checkAllRadios(\"#acknowledgeAll\", \".acknowledgeThis\"); 开发者_StackOverflow社区 checkAllRadios(\"#confirmAll\", \".confirmThis\");
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

精彩评论

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