简体   繁体   English

未捕获的TypeError:无法在phonegap中将属性'innerHTML'设置为null

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

I am trying a pass an array consisting of barcode scanned code in my barcode scannin app using phonegap plugins. 我正在尝试使用phonegap插件通过条形码扫描应用程序中的条形码扫描代码组成的数组。 I am getting an error "Uncaught TypeError: Cannot set property 'innerHTML' of null ". 我收到一个错误“未捕获的TypeError:无法将属性'innerHTML'设置为null”。 In the following code I have used a var k=0; 在以下代码中,我使用了var k=0; and have declared an array var code= new Array(100); 并声明了一个数组var code= new Array(100); in the javascript file previously. 在之前的javascript文件中。

here is my html file 这是我的html文件

<!doctype html>
<html>
<head>
<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>
     <p />
      <p />
         <div  ng-controller="controller">
     <table ng-repeat="result in results">
                <tr>
                    <td>
                      S.No
                    </td>
                    <td >
                    Barcode
                    </td>

                </tr>
                <tr>
                    <td >
                       1
                    </td>
                    <td
                  id="d">
                  </td>                       
                </tr>
                <tr>
                    <td >
                       2
                    </td>
                    <td
                       id="code[0]">
                    </td>
                </tr>
                <tr>
                    <td >
                       3
                    </td>
                    <td
                        id="code[1]">
                    </td>
                    </tr>
        <tr><td><input class="butt" type="button" value="New Scan" onclick="scanCode();" /></td></tr>
            </body>
     <script type="text/javascript">
       var barcodeVal = localStorage.getItem("myvalue");
       document.getElementById("d").innerHTML = barcodeVal;
       </script>
    <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("myvalue1", result.text);
              window.location.href = 'page5.html';

          }, function (error) {
              alert("Scan failed: " + error);
          });
  }
      </script>
      <script type="text/javascript">
      var barcodeVal = localStorage.getItem("myvalue1");
       document.getElementById("code[k]").innerHTML = barcodeVal;
        k=k+1;
      </script>
    </html>

In the following code i am tryin to scan barcode again and again and store the values in an array code[] . 在下面的代码中,我尝试一次又一次地扫描条形码并将值存储在数组code[] But i am getting the error. 但是我得到了错误。 plz help me. 请帮助我。 How should i solve the following issue.I am using phonegap-1.4.1 and barcode scanning plugin for android.Thanks in advance. 我应该如何解决以下问题。我正在使用phonegap-1.4.1和android的条形码扫描插件。

Pease Change : 豌豆变化:

   <script type="text/javascript">

//space in bas codeVal--is wrong
          var bar codeVal = localStorage.getItem("myvalue1");
           document.getElementById("code[k]").innerHTML = barcodeVal;
            k=k+1;
          </script>

TO: 至:

 <script type="text/javascript">
      var barcodeVal = localStorage.getItem("myvalue1");
      document.getElementById("code[0]").innerHTML = barcodeVal ;
       k=k+1;
   </script>

If your code is an array then use as below: 如果您的code是数组,则使用以下code

document.getElementById(code[index]).innerHTML = barcodeVal ;

change this 改变这个

document.getElementById("code[k]").innerHTML = barcodeVal;

to

document.getElementById(code[k]).innerHTML = barcodeVal;

Because code is an array and you are trying to get element using its index. 因为code是数组,所以您尝试使用其索引获取元素。

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

相关问题 未捕获的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 未捕获的TypeError:无法设置null的属性&#39;innerHTML&#39; - Uncaught TypeError: Cannot set property 'innerHTML' of null 错误:TypeError:无法在phonegap中将属性&#39;innerHTML&#39;设置为null - Error: TypeError: Cannot set property 'innerHTML' of null in phonegap 未捕获的TypeError:无法使用for循环将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null using a for loop 未捕获的TypeError:无法在第34行中将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null in line 34 Uncaught TypeError:无法在JS创建的div上将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null on JS created div 未被捕获的TypeError:无法将属性&#39;innerHTML&#39;设置为null [VueJs] - Uncaught TypeError: Cannot set property 'innerHTML' of null [VueJs]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM