请问如何用js获取想要的div里面的信息
如何获得;id":29335033342这断数字 展开
var resultId=data.content.id;
不管你用什么 能得到那数字么
window.onload=function(){
var dd=document.getElementById('dd');
alert(dd.getAttribute('data-field'));
}
给那个div添加一个id="dd",通过上面的js代码能获得data-field的所有值。
还有,data-field的值应该用双引号括起来,双引号里面则应该用单引号。
当然方便点也可以,用单引号把data-field的所有值括i起来。例如:
<div id="dd" class="l_post " data-field='{"author":{"id":205436157,"name":"wurzziyoon","name_u":"wurzziyoon","gender":2,"portrait":"fdb47775727a7a69796f6f6e3e0c","has_grade":true,"grade_level":3,"grade_name":"\u9ad8\u7ea7\u7c89\u4e1d","grade_exp":20,"fans_num":9,"is_concerned":false,"is_private":false,"outer_id":"117730525"},"content":{"id":29335033342,"is_anonym":false,"open_id":"tieba","open_type":"","date":"2013-02-14 19:36","vote_crypt":"","floor":5,"type":"0"}}' data-passive="loaded"></div>