简体   繁体   English

错误:TypeError:无法在phonegap中将属性'innerHTML'设置为null

[英]Error: TypeError: Cannot set property 'innerHTML' of null in phonegap

Here is my javascript file below and i am getting the error "Error: TypeError: Cannot set property 'innerHTML' of null" . 这是下面的我的JavaScript文件,并且出现错误“错误:TypeError:无法将属性'innerHTML'设置为null”。 What changes should i make so that it works fine. 我应该进行哪些更改才能使其正常工作。 Thanks in advance. 提前致谢。 Please help. 请帮忙。

var scanCode = function() {
window.plugins.barcodeScanner.scan(
    function(result) {

    alert("Scanned Code: " + result.text 
            + ". Format: " + result.format
            + ". Cancelled: " + result.cancelled);
            document.getElementById("d").innerHTML="result.text";
            window.location.href = 'page5.html';

}, function(error) {
    alert("Scan failed: " + error);
});
}

I am getting the error as: 我得到的错误为:

06-24 11:55:08.130: W/FlashlightManager(7817):  at   java.lang.reflect.Method.invoke(Method.java:511)
06-24 11:55:08.130: W/FlashlightManager(7817):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-24 11:55:08.130: W/FlashlightManager(7817):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-24 11:55:08.130: W/FlashlightManager(7817):  at dalvik.system.NativeStart.main(Native Method)
06-24 11:55:08.540: D/OpenGLRenderer(7817): Flushing caches (mode 0)
06-24 11:55:08.870: D/OpenGLRenderer(7817): Flushing caches (mode 0)
06-24 11:55:14.920: D/PhoneGapLog(7817): Error in success callback: BarcodeScanner2 = TypeError: Cannot set property 'innerHTML' of null
06-24 11:55:14.920: D/PhoneGapLog(7817): file:///android_asset/www/phonegap-1.4.1.js: Line 692 : Error in success callback: BarcodeScanner2 = TypeError: Cannot set property 'innerHTML' of null
06-24 11:55:14.930: I/Web Console(7817): Error in success callback: BarcodeScanner2 = TypeError: Cannot set property 'innerHTML' of null at file:///android_asset/www/phonegap-1.4.1.js:692

here is the HTML code where i am calling the above js function 这是我调用上述js函数的HTML代码

<!DOCTYPE HTML>
  <html>
  <head>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
   <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no,   width=device-width">
     <title>Bar Code Scanner</title>
   <link rel="stylesheet" href="main.css" type="text/css">

  <script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script>
  <script type="text/javascript" src="barcodescanner.js"></script>
   <script type="text/javascript" src="main.js"></script>
  </head>
  <body id="stage" class="theme">
   <h1>Barcode Scanner and Encoder</h1>
   <h2>PhoneGap Barcode Scanner Plugin</h2>

    <a href="#" class="btn" onclick="scanCode();">Scan Code</a>


 </body>
 </html>

and here is another html file where i need to print the result. 这是我需要打印结果的另一个html文件。

<!doctype html>
 <html>
 <head>
<script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script>
 <script type="text/javascript" src="main.js"></script>
   </head>
   <body>
       <p id="d"></p>
       </body>
      </html>

Try this :: 尝试这个 ::

Page1.html: Page1.html:

  <!DOCTYPE HTML>
  <html>

  <head>
      <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
      <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no,   width=device-width">
      <title>Bar Code Scanner</title>
      <link rel="stylesheet" href="main.css" type="text/css">

      <script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script>
      <script type="text/javascript" src="barcodescanner.js"></script>
  </head>

  <body id="stage" class="theme">
      <h1>Barcode Scanner and Encoder</h1>
      <h2>PhoneGap Barcode Scanner Plugin</h2>

      <a href="#" class="btn" onclick="scanCode();">Scan Code</a>


  </body>
  <script type="text/javascript">
      var scanCode = function () {
          window.plugins.barcodeScanner.scan(
              function (result) {

                  alert("Scanned Code: " + result.text + ". Format: " + result.format + ". Cancelled: " + result.cancelled);
                  localStorage.setItem("myvalue", result.text);
                  window.location.href = 'page2.html';

              }, function (error) {
                  alert("Scan failed: " + error);
              });
      }
  </script>

  </html>

Page2.html Page2.html

<!DOCTYPE html>
<html lang="en">

  <head>
      <title>Checkd Control</title>
      <meta charset="UTF-8">
      <script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script>

  </head>

  <body>
      <p id="d"></p>
  </body>
  <script type="text/javascript">
      var barcodeVal = localStorage.getItem("myvalue");
      document.getElementById("d").innerHTML = barcodeVal;
  </script>

</html>

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

相关问题 未捕获的TypeError:无法在phonegap中将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null in phonegap 未捕获的TypeError:无法设置null错误的属性&#39;innerHTML&#39; - Uncaught TypeError: Cannot set property 'innerHTML' of null error 未捕获的TypeError:无法将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null 未捕获的Typeerror:无法将属性innerHTML设置为null - Uncaught Typeerror: Cannot set property innerHTML of null 未捕获的TypeError:无法将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null 未捕获的TypeError:无法将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null 类型错误:无法在 reactJS 中设置 null 的属性“innerHTML” - TypeError: Cannot set property 'innerHTML' of null in reactJS getElementById TypeError:“无法将属性&#39;innerHTML&#39;设置为null - getElementById TypeError: "cannot set property 'innerHTML' of null 类型错误:无法设置 null 的属性“innerHTML” - TypeError: Cannot set property 'innerHTML' of null 未捕获的TypeError:无法设置null的属性&#39;innerHTML&#39; - Uncaught TypeError: Cannot set property 'innerHTML' of null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM