jQuery select where attribute = value

2019-02-17 14:06发布

问题:

I am trying to select an input where the value equals a dynamic value

trimmed = jQuery.trim(a);
preSelectedCheckBox = $(this).find("input[value=" + trimmed + "]"); 

The element exists but I constantly get no value returned. ($(preSelectedCheckBox).length = 0)

回答1:

Are you just missing the enclosing single quotes?

trimmed = jQuery.trim(a);
preSelectedCheckBox = $(this).find("input[value='" + trimmed + "']");


回答2:

preSelectedCheckBox = $(this).find("input[value=" + trimmed + "]");

forget the '' around the value