试试这个: example
HTML:
<label for="myinput">Label for input</label>
<input id="myinput" />
<button>check</button>
<br />
JS:
$.expr[':'].value = function(obj, index, meta, stack){
if (meta[3] == $(obj).val())
return true;
return false;
};
$.fn.labelInput = function() {
if (this && $(this).attr('id'))
return $('label[for="'+$(this).attr('id')+'"]');
return null;
}
$('button').bind('click', function(event) {
var
inputvalue = $('input').val(),
cssOpcions = {
'-webkit-transition': 'opacity 0.4s linear',
'opacity': '0'
};
$('input:value(' + inputvalue + ')')
.css(cssOpcions)
.labelInput().css(cssOptions);
});
你有没有使用'$(本)'的.VAL(),而不是考虑' $(本).attr( '值')'?哦,属性 - 等于选择器需要引用这些值。 '行情是强制性的。'参考:['val()'](http://api.jquery.com/val/),[attribute-equals selector](http://api.jquery.com/attribute-equals-selector/)。 – 2011-05-13 18:25:12
你可以发布你的标记吗?它会帮助我们理解你正在尝试做什么 – meouw 2011-05-13 18:28:36