使用jQuery 1.4.2和许多以前的版本,可以选择这样的输入:
在jQuery的较新版本中有没有办法通过价值进行选择?
$('input[value=test]')@H_403_4@但是,在1.4.3及更高版本的情况下,此选择器不工作=(
在jQuery的较新版本中有没有办法通过价值进行选择?
解决方法
$(‘input [value =“test”]’)应该工作正常…
@H_403_4@编辑
@H_403_4@你可以尝试使用if语句,例如:
$("input").keyup(function(e) { if (this.value == 'foo'){ $(this).css('backgroundColor','red'); } else if (this.value == 'bar'){ $(this).css('backgroundColor','green'); } else $(this).css('backgroundColor','white'); });@H_403_4@http://jsfiddle.net/ajthomascouk/HrXVS/