这是我的 html(在 Twig 模板中)
<li id="{{folder.id}}" data-jstree='{"icon":"glyphicon glyphicon-tags", "type":"folder"}' ><a href="#">{{folder.name}}</a>
我正在尝试从“data-jstree”获取“type”的值。
我试过用
var node_id = ref.get_node(sel[i]).id;
var type = $("#"+node_id).attr("data-jstree");
但这给了我这个:{"icon":"glyphicon glyphicon-tag", "type":"tag"} 我只需要类型的值。
提前致谢。
最佳答案
var type = JSON.parse($("#"+node_id).attr("data-jstree")).type
关于javascript - 使用 js 或 jquery 限定 html 数据的范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45169509/