douba05167 2013-07-16 17:32
浏览 93

getElementsByTagName出错

I am trying to read in a html file, and then only display certain parts on the page.

I have currently read in the file using AJAX and the requestData.js file. I can then alert out the whole page using that html variable I have created and that works fine.

However it is then when I try and get all the <p> Tags (or any other tag doesn't work), that it comes up with this error.

TypeError: 'undefined' is not a function (evaluating 'html.getElementsByTagName("div")')

What am I doing wrong here?

<!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>

<script type="text/javascript" language="JavaScript" src="requestData.js"></script>
<script type = "text/javascript">

    function refresh(xmlhttp){
        var html = xmlhttp.responseText;
        var ps = html.getElementsByTagName("p");
    }

</script>

</head>
<body>

</body>

<input type = "submit" onclick = "requestData('home.html', refresh)">

</html>
  • 写回答

3条回答 默认 最新

  • dongyili5843 2013-07-16 17:38
    关注

    html var its just string, use jQuery Framework for parsing it :) Like this jQuery(html).Find('p');

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入