免责声明:这是一种独特的情况,而且非常黑客。
我有一组对用户可见的 radio ,而另一组则隐藏。我需要从隐藏集中提取名称并分配给可见集。
隐藏 radio :
<div class="productAttributeValue">
<div class="productOptionViewRadio">
<ul>
<li>
<label>
<input type="radio" class="validation" name="attribute[139]"
value="86" checked="checked" />
<span class="name">Standard Shipping</span>
</label>
</li>
etc etc...more li's
</ul>
</div>
</div>
可见的 radio :
<label>
<input type="radio" class="validation" name="PUT OTHER NAME HERE" value="86" checked="checked" />
<span class="name">Standard Shipping</span>
<p class="rl-m"><small>Earliest Date of Delivery:</small>
<small><span id="delivery-date"></span></small></p>
</label>
因此,在这种情况下,我希望以某种方式从隐藏的 radio 中获取名称“attribute[139]”并调用可见 radio 的名称。我正在考虑这样的事情:
<script>
$(function() {
var name = $(".productOptionViewRadio span.name:contains('(Standard)')").attr('name');
});
</script>
我不太确定脚本是否是解决此问题的正确方法,也不确定如何实际从一个元素获取值以填充到另一个元素的名称字段。
非常感谢。
更新: fiddle http://jsfiddle.net/susan999/XBcaF/
最佳答案
尝试
$('label input[type=radio]').attr('name',
$('.productOptionViewRadio input[type=radio]').attr('name'));
关于javascript - 从一个元素获取名称并调用另一元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20293609/