I want select every inputbox o开发者_运维技巧f type text and transform by a fixed amount, when checkbox is checked, so far I have this. However I wondered if there was a way to do this without iterating over every element ...
$("#myID").change(function(){
if($(this).is(':checked')){
//I can't do this :
$("input:text").val( $("input:text").val()*4);
//I have to do this ?
$("input:text").each(function(index){
$(this).val($(this).val()*4);
});
});
If you are using jQuery 1.4+, you can use a function callback to calculate the value:
$("input:text").val(function(idx, oldVal) {
return oldVal * 4;
});
See the API.
精彩评论