weixin_33725515 2016-04-16 17:59 采纳率: 0%
浏览 2

警报(reponseText + $(。class))

I want print Hello World. but it doesn't work. Why? The problem is in line 30, how can I change this line for print "Hello World." by class "example"? I already tryed var x = y.getElementsByClassName("example"); and var x = variavelhtttp.responseXML.getElementsByClassName("example"); but without success.

index.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <title>Load page</title>

    <script src="https://code.jquery.com/jquery-1.10.2.js"></script>

    <script type="text/javascript">
    if(window.XMLHttpRequest){
    variavelhtttp = new XMLHttpRequest();
    }else{
    alert("Withouth Ajax!");
    }
    </script>

</head>

<body>

    <button type="button" onclick="loadDoc()">Go</button>

    <script type="text/javascript">
        function loadDoc(){
            variavelhtttp= new XMLHttpRequest();
            variavelhtttp.open("GET","text.html",false);
            variavelhtttp.send();
            var y = variavelhtttp.responseText;
            window.alert(y);
            var x = $( ".example" ).html(y);
            alert(x);
         }
    </script>

</body>
</html>

text.html

<html>
<head>
    <title></title>
</head>
<body>
    <div class="example">Hello World.</div>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • weixin_33709219 2016-04-16 18:25
    关注

    $( ".example" ).html(y) SETS value y inside .example

    and var x = $( ".example" ).html(y); will make x an object, as you can see with alert(x);

    The alert you wanted:

    alert(  $( ".example" ).html() );
    

    OR

    alert(  $( ".example" ).text() );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)