无法从循环数据属性的内容中获取索引的值
Can't get the value of the index from the contents of a looped data attribute
下面是我的片段,因此为了锐化细节,首先我遍历当前单击的元素具有的每个数据属性,获取内容并按"%"将其拆分为分隔符并循环每个拆分的内容。现在,我试图做的是提醒索引为"0"的内容(您可以在"if"语句中看到,如果索引"0"则提醒索引[0]值),但似乎不起作用,甚至没有传递提供的if语句。任何想法,线索,建议,建议,请帮忙?
$(document).ready(function(){
$("button").click(function(){
$.each($(this).data(),function(index,value){
if(index !== "plugin_ripples"){
var classList = value.split("%");
$.each(classList, function(index, item) {
alert("index: "+index+" index value: "+item);
if(index[0]){
alert(index[0].item);
}
});
}
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button data-name="test%jason%kayko" data-test="test 2">test</button>
由于没有人就我想要实现的目标给我不同的方法,所以我为自己创建了一个不同的方法来满足我的需求和要求,我所做的是将其与数组连接起来,请查看下面的代码片段。
$(document).ready(function(){
$("button").click(function(){
$.each($(this).data(),function(index,value){
if(index !== "plugin_ripples"){
var classList = value.split("%");
var data_items = [];
$.each(classList, function(index, item) {
data_items.push(item);
});
if(data_items[0] === "null"){
alert(data_items[0]);
}
}
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button data-name="test%jason%kayko" data-test="test 2">test</button>
相关文章:
- 对于关于es6-获取索引如何
- AngularJS ng选项获取索引
- Javascript点击即可获取索引
- 按值获取索引
- 在Chrome上获取z索引值时存在差异
- 循环对象以获取索引值
- 快速从 2D 数组获取索引,无需迭代 jquery
- 无法从循环数据属性的内容中获取索引的值
- 在 JavaScript 数组中按值获取索引
- 获取索引处字符的 ANSI 颜色
- 我知道如何获取 z 索引,但是有没有办法在页面上获取绝对 Z(数字,而不是 AUTO)
- 使用自定义Knockout映射时获取索引值
- 如何在不计算隐藏元素的情况下获取索引
- 正在从对象获取索引
- 如何从父元素获取索引值
- 从多维数组中获取索引
- 如何检测当前输入文本'使用jquery从输入文本数组中获取s索引
- 如何获取索引元素
- 在javascript的多维数组中获取索引
- 在javascript foreach循环中获取索引