Ios 如何用html文件调用js文件
我可以将js文件插入html文件吗? 我已经试过了,但无法加载js文件 lib.jsIos 如何用html文件调用js文件,ios,uiwebview,Ios,Uiwebview,我可以将js文件插入html文件吗? 我已经试过了,但无法加载js文件 lib.js function alertMeWithMyCustomFunction(text) { alert(text+' -> in lib.js'); } Test.html <!DOCTYPE html> <html> <head> <title>MathJax</title> <script
function alertMeWithMyCustomFunction(text) {
alert(text+' -> in lib.js');
}
Test.html
<!DOCTYPE html>
<html>
<head>
<title>MathJax</title>
<script type=\"text/javascript\" src=\"lib.js\" />
<script type=\"text/javascript\" src=\"MathJaxUnpacked/MathJax.js\"></script>
<script type=\"text/x-mathjax-config\">MathJax.Hub.Config({tex2jax: {inlineMath: [[\"$\",\"$\"],[\"\\(\",\"\\)\"]]}});</script>
</head>
<body>
<br>
<a href=\"javascript:alertMeWithMyCustomFunction('I am');\">External js test</a>
<br>
<br>
<a href=\"javascript:alert('Works!')\">Test Javascript Alert</a>
<br>
<h1>MathJax Test</h1>
<br>
<p>Here the HTML is dynamically inserted using loadHTMLString in a UIWebView, and the JavaScript and image are referenced from the resources of the application.</p>
<br>
<p>$$\\int_x^y f(x) dx$$</p>
<br>
<br>
<img src=\"images/test.jpg\">
</body>
</html>
我哪里做错了?我没有文件夹结构文件在项目中默认文件夹结构它自己。
当我点击链接时,什么都不会发生检查UIWebView方法,该方法称为: stringByEvaluatingJavaScriptFromString:NSString*脚本
NSString *result = [_webView stringByEvaluatingJavaScriptFromString:(@"alert('test')
你必须调用javascript函数我猜你的js文件由于某种原因没有加载,因为一个错误的引用问题。你的html文件在哪里?html和js文件是否都位于同一位置?您是否尝试使用带有Safari开发人员检查器的模拟器来查找javascript错误/文件加载问题?这两个文件位于同一位置。它不起作用,因为我直接在html文件中使用脚本
NSString *result = [_webView stringByEvaluatingJavaScriptFromString:(@"alert('test')