jquery input selection
var inputvalue = $(this).attr('value')
$('input[value=inputv开发者_C百科alue] + label').css({
'-webkit-transition': 'opacity 0.4s linear',
'opacity': '0'
});
But it does not work. As expected value=inputvalue does not get that variable but looks for that name. How can i do this?
Thanks a lot :)
You need to use some string concatenation here.
var inputvalue = $(this).val();
$('input[value="' + inputvalue + '"] + label').css({
'-webkit-transition': 'opacity 0.4s linear',
'opacity': '0'
});
try this: 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);
});
精彩评论