简体   繁体   English

this.value仅返回前两个字符

[英]this.value only returning first two characters

I'm attempting to find the value of all elements with the class bm-user-label, and put it into a javascript array. 我正在尝试使用bm-user-label类查找所有元素的值,并将其放入javascript数组中。 However when I do this I only get the first two characters of the value field. 但是,当我这样做时,我只会得到value字段的前两个字符。 For instance for: 例如:

value="30bb3825e8f631cc6075c0f87bb4978c"

I get returned 我回来了

30

The DOM looks like DOM看起来像

<li value="30bb3825e8f631cc6075c0f87bb4978c" class="cboxElement bm-user-label">first</li>

And my javascript is: 我的JavaScript是:

var com_labels = $('.bm-user-label').map(function() {
     return(this.value);
}).get();

Any ideas? 有任何想法吗?

<li> elements are not defined to have a value. <li>元素未定义为具有值。 You should get this attribute using this.getAttribute("value") instead. 您应该改为使用this.getAttribute("value")获得此属性。

In an effort to follow the doctype standards, you should use data attributes for non-native attributes: 为了遵循文档类型标准,应将数据属性用于非本地属性:

<li data-value="30bb3825e8f631cc6075c0f87bb4978c" class="cboxElement bm-user-label">first</li>

And query it as such: 并这样查询:

var com_labels = $('.bm-user-label').map(function() {
     return($(this).data('value'));
}).get();

http://jsfiddle.net/sTdWY/ http://jsfiddle.net/sTdWY/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM