[英]jQuery Selector wild card selector attribute as object parameter
I want to use the progressbar UI widget on multiple elements. 我想在多个元素上使用progressbar UI小部件。 The value I want to pass is the actual attribute of the element.
我要传递的值是元素的实际属性。 How do I achieve this?
我该如何实现?
I have tried these but they don't work: 我尝试了这些,但它们不起作用:
$('[id^=pkg]').progressbar({value: $(this).attr('value')});
$('[id^=pkg]').progressbar({value: $([id^=pkg]).attr('value')});
I do get a value for: 我确实得到了一个价值:
$([id^=pkg]).attr('value')
Apologies but this was missing: 抱歉,但是缺少:
<div id="pkg1" value="30"><div class="progress-label"></div></div>
Which required parseInt(). 哪个需要parseInt()。
You may need to iterate and initiate each at a time? 您可能需要一次迭代并初始化每个?
$('[id^=pkg]').each(function() {
$(this).progressbar({value: $(this).attr('value')});
});
Option 1 Won't work because the value of this
is not what you expect it to be. 选项1不起作用,因为价值
this
是不是你希望它是什么。
$('[id^=pkg]').progressbar({value: $(this).attr('value')});
$('[id^=pkg]').each(function() {
var $this = $(this);
$this.progressbar({
value: $this.attr('value')
});
});
Btw, It's better to use class name instead of [id^=pkg]
顺便说一句,最好使用类名代替
[id^=pkg]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.