分别为每个输入显示占位符文本

时间:2015-12-14 08:48:40

标签: javascript jquery html

我有以下代码:

    <div>
  <input data-maxsale="9" data-maxsaleid="27595" name="cart[3839][qty]" value="1" title="Qty" class="input-text qty" maxlength="12">
  <div class="maxsalenotifcation maxsaleid-27595">
    <p>
      placeholder
    </p>
  </div>
</div>
<div>
  <input data-maxsale="3" data-maxsaleid="27757" name="cart[3841][qty]" value="1" title="Qty" class="input-text qty" maxlength="12">
  <div class="maxsalenotifcation maxsaleid-27757">
    <p>
      placeholder
    </p>
  </div>
</div>

var maxSalInput = $('input[data-maxsaleid]');
$('.maxsalenotifcation').hide();

maxSaleInputs.each(function() {

  var maxSaleID = $(this).attr('data-maxsaleid');
  var maxSaleValue = $(this).val();
  var maxSaleQuantity = $(this).attr('data-maxsale');

  if (maxSaleValue > maxSaleQuantity) {
    $('.maxsalenotifcation .maxsaleid-' + maxSaleID).show();
  }

});

http://jsfiddle.net/bmpqo69g/

当输入值大于placeholder时,我想为每个maxsaleid单独显示maxSaleValue

如果需要,我可以修改html标记。

我该怎么做?

1 个答案:

答案 0 :(得分:0)

  1. 尚未定义此compileSdkVersion变量。
  2. 您应该定义多个类,例如maxSaleInputs(类之间没有空格)
  3. 代码段:

    $('.maxsalenotifcation.maxsaleid-' + maxSaleID)
    $(function() {
      var maxSalInput = $('input[data-maxsaleid]');
      $('.maxsalenotifcation').hide();
    
      maxSalInput.each(function() {
    
        var maxSaleID = $(this).attr('data-maxsaleid');
        var maxSaleValue = parseInt($(this).val());
        var maxSaleQuantity = parseInt($(this).attr('data-maxsale'));
    
        if (maxSaleValue > maxSaleQuantity) {
          $('.maxsalenotifcation.maxsaleid-' + maxSaleID).show();
        }
    
      });
    });