Combing selectors that are saved as vars
I know it's possible to combine the first 2 lines to something like line 3 where the 2 selectors are separated by ,
$('#divid input[name=some]').val('');
$('#divid input[name=thing]').val('');
$('#divid input[name=some], #divid input[name=thing]').val('');
But if I have them saved as objects obj1
and obj2
, how do I select them together the same way?
var obj1 = $('#divid input[name=some]');
var obj2 = $('#divid input[name=thing]开发者_StackOverflow');
I tried all this but they didn't work. Can it be done?
obj1,obj2.val('');
(obj1,obj2).val('');
$(obj1,obj2).val('');
You can use the add() method:
var obj1 = $('#divid input[name=some]');
var obj2 = $('#divid input[name=thing]');
obj1.add(obj2).val('');
Try
var object = $.extend({}, object1, object2);
Reference
精彩评论