我正在尝试通过 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 中没有“字符串”
添加回答
举报
0/150
提交
取消