我有这个HTML源代码:
<div id='fbResponse' style='display:none'>{"key1":"value1","key2":"value2"}</div>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
....
</script>
</head>
<body onload="initFB()" style="text-align: center">
....
</body>
</html>
如何获取id为“fbResponse”的div标签的内容文本, 我已经尝试了功能
document.getElementById('tag id'),
它不起作用,我认为是因为标签:
<div id='fbResponse' style='display:none'>{"key1":"value1","key2":"value2"}</div>
不在“文件”中。
修改 我需要它的浏览器是移动Safari(iOS)
答案 0 :(得分:0)
<div id='fbResponse' style='display:none'>{"key1":"value1","key2":"value2"}</div>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
console.log(document.getElementById('fbResponse'));
</script>
</body>
</html>
即使在IE中也有一个日志...我认为你做错了