Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何用html文件调用js文件_Ios_Uiwebview - Fatal编程技术网

Ios 如何用html文件调用js文件

Ios 如何用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

我可以将js文件插入html文件吗? 我已经试过了,但无法加载js文件

lib.js

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')