【问题标题】:Get custom attribute value using Next() by Class使用 Next() by Class 获取自定义属性值
【发布时间】:2014-03-04 18:18:32
【问题描述】:

我希望使用 next() 按类获取图像中自定义属性的值。

$("#chkSell").live('change',function(){
     var posType = $(this).next('img[class="qtyImgDD"]').attr('posType');
});
<div class="Sell" style="width: 47px;"><input type="checkbox" fund-id="1" id="chkSell" class="_1"/></div>
<div class="Buy" style="width: 47px;"><input type="checkbox" fund-id="1" id="chkBuy" class="_1"/></div>
<div class="BuySelllbl" style="width: 10px;"><label class="lblBuySell_1" fund-id="1">&nbsp;</label></div>
<div class="Amt" style="width: 116px;"><input type="textbox" fund-id="1" id="AmtValue" size="8" disabled="disabled"/></div>
<div class="QtyType" style="width: 55px;"><label class="lblQtyType" fund-id="1" ddclass="_1">D</label>&nbsp;

<img src="/Applications/Images/ModelManagement/DropDown_Disabled.gif" fund-id="1" posType="MutualFund" class="qtyImgDD" disabled="disabled" ddclass="_1"/></div>

我想要的是当有人单击 chkSell 复选框并执行 change() 函数以从底部获取 posType 属性值时?

【问题讨论】:

  • 你遇到了什么问题??
  • 当我明确提出问题并用正确的代码引用和 HTML 表达我的问题时,为什么你会反对我的观点?

标签: jquery custom-attributes attr next


【解决方案1】:

您可能想要更改一些小事情。将“live”切换为“on”,将“next”切换为“nextAll”,将“img[class="qtyImgDD"]”更改为img.qtyImgDD。

$("#chkSell").on('change',function(){
     var posType = $(this).parent().nextAll('.QtyType').find('img.qtyImgDD').attr('posType');
});

Next 只是直接兄弟,而nextAll 是所有后续兄弟。

此外,您拥有的标记没有您定位为直接兄弟的元素。所以你需要遍历他们的父母。


参考:

【讨论】:

  • 这很好用,非常感谢您的帮助,我会在 nextAll 文档上做更多阅读,我不熟悉。
猜你喜欢
  • 2021-12-28
  • 2015-04-18
  • 2013-05-30
  • 2015-04-26
  • 1970-01-01
  • 1970-01-01
  • 2023-03-03
  • 2015-05-06
  • 1970-01-01
相关资源
最近更新 更多