試試這個: 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