下面,您可以找到我正在使用的“选定”-Object的屏幕截图。这是一个选择列表。我收到以下代码的对象(使用jQuery):通过变量访问数据属性值
var addArticle = $('.add-article'); // div.add-article
// selector is a dynamic value, that defines, which select-list should be "found"
var select = addArticle.find('[data-id=' + selector + ']');
对象选择正常。但是,当我想获得数据属性值(值是数字),我无法得到它们。
我试了很多变化,以获取值,但这里是它的一个例子
//$this.selectors is an array with all values beween data- and -id
$.each($this.selectors, function (i, el) {
//return if last needed data attribute was read
if (i == $this.lastAsInt) {
return false;
}
// "generate" data-selector
selector = '[data-' + el + '-id]';
// select = object from the image (see link), also tried with data()
location[el] = select.find(':selected').find(selector);
});
我希望有人能理解我的问题:)
它真的不清楚你问什么,但如果你想从'data'选择元素属性您打造'selector',那么你需要像这样将它包装在'[]'中:'selector ='[data-'+ el +'-id]';'。如果这不是你所需要的,那么请编辑你的问题,以使你想要做的更清楚 –