我使用loadHTMLString
方法加载HTML字符串。
self.webview.loadHTMLString("the html", baseURL:nil)
html的内容如下:
<!DOCTYPE html>
<html>
<head>
<script src="http://cdn.bootcss.com/jquery/2.1.4/jquery.js">
</script>
<script>
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
});
});
</script>
</head>
<body>
<p> Tap me to hide</p>
</body>
</html>
结果并不顺利。 javascript代码没有执行。但是,当我将<script src="http://cdn.bootcss.com/jquery/2.1.4/jquery.js">
更改为本地baseURL
并提供正确的{{1}}时,它会正常运作。
答案 0 :(得分:0)
正如@matt所提到的,它是关于https
。
远程JavaScript必须是https
个。当我将脚本更改为"https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"
时,它可以正常工作。
我在iOS 9 / 8.4,UIWebView / WKWebView上测试它们都需要https
。