我在使用 Jsoup 中的 .append 函数时遇到问题。我将简单的 Javascript 文件响应字符串附加到 Jsoup 元素。但在附加后,我的回复变成了一行,这对我造成了很大的伤害。
我的字符串是这样的
(function () {
var count = 0;
var root = this;
var require = root.require;
//var require = cordova.require;
require.config({
config: {
text: { //this hacks the text api to allow cross domain loading of the templates. it is needed only for the packaged applications
useXhr: function (url, protocol, hostname, port) {
//console.log("text.useXhr request came from : " + url + ", " + protocol + " and " + hostname);
return true;
//return true if you want to allow this url, given that the
//text plugin thinks the request is coming from protocol, hostname, port.
}
},
'is': {
isBundled: true
}
},
waitSeconds: 45,
baseUrl: 'scripts/app',
deps: ["app"],
但是附加到元素后,它会变成
(function () { var count = 0; var root = this; var require = root.require; //var require = cordova.require; require.config({ config: { text: { //this hacks the text api to allow cross domain loading of the templates. it is needed only for the packaged applications useXhr: function (url, protocol, hostname, port) { //console.log("text.useXhr request came from : " +
我的代码就是用于此
String temp=script.attr("src");
temp=temp.replace("/"+Heirarchy, DomainName+"/"+Heirarchy.toLowerCase());
script.attr("src", temp);
script.removeAttr("data-main");
script.removeAttr("async");
String innerHtml="</script>\n<script>\n"+old_configString;
script.append(innerHtml);
old_configString 是我的 Javascript 响应字符串....
最佳答案
您应该使用 DataNode用于添加脚本或样式。
script.after(new DataNode("<script>" + old_configString + "</script>", "http://domain.tld/path"));
关于java - Jsoup 将我的 javascript 字符串转换为一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23925988/