【问题标题】:Filter input by name[] in jQuery [duplicate]在jQuery中按名称[]过滤输入[重复]
【发布时间】:2017-04-22 17:04:22
【问题描述】:

我有一个小脚本,可以将值粘贴到不同的输入中。

<input name="BOO_Price">
<a id="repeatPrice">Repeat</a>
<input name="BOO_Price">
<input name="BOO_Price">
<input name="BOO_Price">
<input name="BOO_Price">


$('#repeatPrice').on('click', function(e) {
    e.preventDefault();
    var price = $(this).prev('input').val();
    $('input[name=BOO_Price]').val(price);
});

效果很好。

但现在我的输入表单是这样的。

<input name="BOO_Price[]">

但这不起作用:

$('input[name=BOO_Price[]]').val(price);

理想情况下,我不想拥有一些id 或其他类型的classes


你能帮忙吗?

【问题讨论】:

    标签: jquery


    【解决方案1】:

    用引号将属性值括起来,因为值包含元字符。

    $('input[name="BOO_Price[]"]').val(price);
    

    或者使用\\转义元字符。

    $('input[name=BOO_Price\\[\\]]').val(price);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-11
      • 2013-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-02
      • 2013-11-29
      • 1970-01-01
      相关资源
      最近更新 更多