开发者

jquery input selection

开发者 https://www.devze.com 2023-03-05 13:45 出处:网络
var inputvalue = $(this).attr(\'value\') $(\'input[value=inputv开发者_C百科alue] + label\').css({
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);

});
0

精彩评论

暂无评论...
验证码 换一张
取 消