外部脚本在Windows Phone App 8.1中不起作用 [英] External scripts not working in Windows Phone App 8.1

查看:250
本文介绍了外部脚本在Windows Phone App 8.1中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了一个的WebView到我的项目。如果我浏览到包含他们不工作外部JavaScript文件,HTML文件。位如果我写硬编码到它正常工作HTML文件中的JavaScript代码。



下面是HTML部分:

 < DOCTYPE HTML PUBLIC -  // W3C // DTD HTML 4.01 // ENhttp://www.w3.org/TR/html4/strict.dtd\"> 
< HTML LANG =EN的xmlns =http://www.w3.org/1999/xhtml>
< HEAD>
<间的charset =UTF-8/>
<标题>< /标题>
<脚本类型=文/ JavaScript的SRC =testjs.js>< / SCRIPT>
< /头>
<身体GT;
< DIV ID =ABCD>< / DIV>
< BR />
您好!这是一个简单的HTML块。
< /身体GT;
< / HTML>

下面是JavaScript部分:

 的document.getElementById(ABCD)的innerHTML =新文本!。 

当我打开它显示



您好!这是一个简单的HTML块。



但如果JavaScript代码工作它会显示



新的测试!
您好!这是一个简单的HTML块



下面是文件夹结构:




解决方案

SRC =testjs.js是正确的。问题是不相关的路径。



[更新1]



您代码应工作就像我们平时用于Web开发做。但似乎我们需要确保在脚本中使用的HTML元素已初始化,所以我们必须把身体元素的结尾。请尝试以下的html代码:



<预类=片段 - 代码HTML语言,HTML prettyprint-覆盖> <!DOCTYPE HTML PUBLIC - // W3C // DTD HTML 4.01 // ENHTTP ://www.w3.org/TR/html4/strict.dtd>< HTML LANG =EN的xmlns =http://www.w3.org/1999/xhtml>< HEAD> <间的charset =UTF-8/> <标题>< /标题> < /头><身体GT; < DIV ID =ABCD>将< / DIV> < BR />你好!这是一个简单的HTML块。 <脚本类型=文/ JavaScript的SRC =testjs.js>< / SCRIPT>< /身体GT;< / HTML>



[更新2]



另外检查是否已改变了的建立 testjs.js 操作以内容。转至解决方案管理器 - >右键点击 testjs.js - > 属性 - >变化的生成操作内容。这将确保的.js 文件将被部署为应用你的一部分。


I've added a WebView into my project. If I navigate to the html file that contains external javascript files they don't work. Bit if I write the javascript code hardcoded into the html file it works properly.

Here is the html portion:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <script type="text/javascript" src="testjs.js"></script>
</head>
<body>
    <div id="abcd"></div>
    <br/>
    hello! this is a simple html block. 
</body>
</html>

Here is the javascript portion:

document.getElementById("abcd").innerHTML = "New text!";

When I open the webview it shows

hello! this is a simple html block.,

but if the javascript code worked it would show

New Test! hello! this is a simple html block.

Here is the folder structure:

解决方案

src="testjs.js" is correct. The issue is not related to the path.

[Update 1]

Your code should work as we usually do for web development. But seems we need to make sure the html element used in the script has been initialized, so we have to put the to the end of the body element. Please try the following html code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    
</head>
<body>
    <div id="abcd">a</div>
    <br />
    hello! this is a simple html block.

    <script type="text/javascript" src="testjs.js"></script>
</body>
</html>

[Update 2]

Also check if you have changed the build action for testjs.js to content. go to Solution Explorer -> right click on testjs.js -> Properties -> change Build Action to Content. That will make sure the .js file will be deployed as part of you app.

这篇关于外部脚本在Windows Phone App 8.1中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆