JavaScript 在 Tizen Web Widget 中不起作用 [英] JavaScript not working in Tizen Web Widget

查看:29
本文介绍了JavaScript 在 Tizen Web Widget 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 Tizen Web Widget 应用程序.我的 javaScript 文件位于 MyProject >>小部件 >>我的项目 >>js >>main.js.即使我在 window.onload() 方法中更改元素的文本,它也不起作用.

我还尝试了this 问题,但这对我也不起作用.如果我遗漏了任何其他支票,请有人指导我.

解决方案

在编写 Web Widget 时,最多的问题是由于它支持的功能数量有限.示例是 不支持innerText 和innerHTML,您可以使用它们默认"从javascript 更改html 的内容.

要更改 HTML 元素的内容,您需要使用 textContent 代替.我试图以这种方式重现您的问题:

index.html

<头><meta charset="UTF-8"><link rel="stylesheet" type="text/css" href="css/style.css"><script src="js/main.js"></script><style></style><身体><div id="页面"><div id="container" onclick="changeContent()"><span id="content-text">小部件</span>

</html>

var changed = true;window.onload = 函数(){console.log('[window.onload]');var box = document.getElementById("content-text");box.textContent = "起始内容"};更改内容 = 函数(){var box = document.getElementById("content-text");console.log('changeContent:' + box.textContent)box.textContent = 改变了?"abcdef": "xyz";改变了 = !改变了;};

并且代码在 Tizen 模拟器上运行良好.

您可能使用了不受支持的功能.我建议您仔细检查 Web Widget 不支持的功能,并且不要在您的实现中使用它们.

I'm working on a Tizen Web Widget Application. My javaScript file resides in MyProject >> widget >> MyProject >> js >> main.js. Even if I change the text of an element in the window.onload() method, it doesn't work.

I've also tried the accepted answer of this question but this also didn't work for me. Someone please guide me if there's any other check which I'm missing.

解决方案

When writing a Web Widget, the most problems are caused by fact, that it has limited number of features supported. The example is not supported innerText and innerHTML, which you could used to change the content of html from javascript 'by default'.

To change the content of HTML element you need to use textContent instead. I tried to reproduce your problem this way:

index.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <link rel="stylesheet" type="text/css" href="css/style.css">
  <script src="js/main.js"></script>
  <style></style>
</head>

<body>
  <div id="page">
    <div id="container" onclick="changeContent()">
      <span id="content-text">Widget</span>
    </div>
  </div>
</body>
</html>

var changed = true;
window.onload = function() {
  console.log('[window.onload]');
  var box = document.getElementById("content-text");
  box.textContent = "starting content"
};

changeContent = function() {
    var box = document.getElementById("content-text");
    console.log('changeContent: ' + box.textContent)
    box.textContent = changed ? "abcdef" : "xyz";
    changed = !changed;
};

and code work well on Tizen emulator.

It is possible that you use feature, which is not supported. I suggest you checking carefully about features not supported in Web Widget and just not use them in your implementation.

这篇关于JavaScript 在 Tizen Web Widget 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆