简体   繁体   English

JavaScript 在 Tizen Web Widget 中不起作用

[英]JavaScript not working in Tizen Web Widget

I'm working on a Tizen Web Widget Application .我正在开发Tizen Web Widget Application My javaScript file resides in MyProject >> widget >> MyProject >> js >> main.js .我的 javaScript 文件驻留在MyProject >> widget >> MyProject >> js >> main.js Even if I change the text of an element in the window.onload() method, it doesn't work.即使我在window.onload()方法中更改元素的文本,它也不起作用。

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.在编写 Web Widget 时,大多数问题是由事实引起的,即它支持的功能数量有限。 The example is not supported innerText and innerHTML , which you could used to change the content of html from javascript 'by default'.该示例不支持 innerText 和 innerHTML ,您可以使用它们来“默认”从 javascript 更改 html 的内容。

To change the content of HTML element you need to use textContent instead.要更改 HTML 元素的内容,您需要改用textContent I tried to reproduce your problem this way:我试图以这种方式重现您的问题:

index.html索引.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.和代码在 Tizen 模拟器上运行良好。

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.我建议您仔细检查 Web Widget 中不支持的功能,并且不要在您的实现中使用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM