j查询输入选择

jquery input selection

本文关键字:选择 输入 查询      更新时间:2023-09-26
var inputvalue = $(this).attr('value')
             $('input[value=inputvalue] + label').css({
                    '-webkit-transition': 'opacity 0.4s linear',
                    'opacity': '0'
                });

但它不起作用。正如预期的那样,value=inputvalue 不会获得该变量,而是查找该名称。我该怎么做?

非常感谢:)

您需要在此处使用一些字符串连接。

var inputvalue = $(this).val();
$('input[value="' + inputvalue + '"] + label').css({
  '-webkit-transition': 'opacity 0.4s linear',
  'opacity': '0'
});

试试这个:例

.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);
});