为了账号安全,请及时绑定邮箱和手机立即绑定

SyntaxError:意外标记:尝试将文本转换为 html 时出现标识符问题

SyntaxError:意外标记:尝试将文本转换为 html 时出现标识符问题

四季花海 2021-08-20 15:49:37
我正在尝试通过 jquery 从不同的站点获取 html 代码并将其转换为 html 对象。这是我的代码。<!DOCTYPE html><!--To change this license header, choose License Headers in Project Properties.To change this template file, choose Tools | Templatesand open the template in the editor.--><html>    <head>        <title>TODO supply a title</title>        <meta charset="UTF-8">        <meta name="viewport" content="width=device-width, initial-scale=1.0">        <script src="https://code.jquery.com/jquery-latest.min.js"></script>        <script type="text/javascript">            $.getJSON('http://www.whateverorigin.org/get?url=' + encodeURIComponent('https://www.codewars.com/users/codemzy') + '&callback=?', function (data) {                console.log(data.contents);                string s = data.contents;                var htmlObject = $(s);                alert(htmlObject.querySelector('.has-tip').src);            });        </script>    </head>    <body>    </body></html>在这里,我需要从 url ' https://www.codewars.com/users/codemzy '获取图像 src但不幸的是却收到了这个错误,语法错误:意外标记:标识符我换string s到var s的问题是走了,但现在得到这个问题,类型错误:htmlObject.querySelector 不是函数
查看完整描述

3 回答

?
萧十郎

TA贡献1815条经验 获得超13个赞

我猜:

string s = data.contents;

应该是:

var s = data.contents;

或:

let s = data.contents;

因为 JavaScript 中没有“字符串”


查看完整回答
反对 回复 2021-08-20
  • 3 回答
  • 0 关注
  • 278 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信