可能我使用了错误的方法,但将 Javascript 插入到我的文档中,因为我没有得到预期的输出,这里是我的代码
String serachBoxLeft = "<script type='text/javascript' src='http://website/SearchBox/75070'></script>";
try{
Element search = doc.getElementById("hc_checkPrices").empty();
search = search.appendText(serachBoxLeft);
}catch (Exception e){
}
System.out.println(search);
我得到的输出是
<div id="hc_checkPrices" class="hc_m_v2">
<script type='text/javascript' src='http://website/SearchBox/75070'></script>
</div>
它触发了<>括号的代码
感谢任何帮助
最佳答案
如果方法名称是 appendText()
,很明显它将把给定的字符串视为文本,而不是 HTML 片段。使用Element.append(String html)
method相反。
关于java - 如何输出<>符号而不是<,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15863342/