简体   繁体   English

未捕获的类型错误:无法在加号 (js.js:52) 处设置 null 的属性“值”

[英]Uncaught TypeError: Cannot set property 'value' of null at plus (js.js:52)

Id dind't work !我没用! The javascript said that Uncaught TypeError: Cannot set property 'value' of null at plus (js.js:52) javascript 说 Uncaught TypeError: Cannot set property 'value' of null at plus (js.js:52)

 var count = 1; var countEl = document.getElementById("count"); function plus() { count++; countEl.value = count; } function minus() { if (count > 1) { count--; countEl.value = count; } }
 <div id="input_div"> <input type="text" size="25" value="1" id="count"> <input type="button" value="-" id="moins" onclick="minus()"> <input type="button" value="+" id="plus" onclick="plus()"> </div>

     <div class="col-md-3 py-5">
      <button type="button" class="btn bg-light border rounded-circle">
      <i class="fas fa fa-minus" onclick="minus()"></i></button>
      <input type="text" id="count" value="<?php echo $pro_quantity?>" class="form-control w-25 d-inline">
      <button type="button" class="btn bg-light border rounded-circle">
      <i id="plus" class="fas fa fa-plus" onclick="plus()"></i></button>
     </div>

It's possible that you are not loading your script as <script src="yourfile.js" defer></script> , with that defer attribute in place.您可能没有将脚本加载为<script src="yourfile.js" defer></script> ,并且该defer属性就位。

If not, add that to your HTML, because your code is querying the DOM, and so you only want to do that after the DOM has been created .如果没有,请将其添加到您的 HTML 中,因为您的代码正在查询 DOM,因此您只想在创建 DOM 后执行此操作。 The defer attribute guarantees that will be the case . defer属性保证了这种情况

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

相关问题 js.js:14 未捕获类型错误:无法读取 null 的属性“样式” - js.js:14 Uncaught TypeError: Cannot read property 'style' of null 未捕获的 TypeError:无法设置 null 的属性“innerHTML”-打字机 JS 代码 - Uncaught TypeError: Cannot set property 'innerHTML' of null - Typewriter JS Code Uncaught TypeError:无法在JS创建的div上将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null on JS created div 未捕获的类型错误:无法读取 null 的属性“值”(React/JS/TS) - Uncaught TypeError: Cannot read property 'value' of null (React/JS/TS) HTML,JS,接收未捕获的类型错误:当变量具有值时,无法将属性“innerHTML”设置为 null - HTML, JS, receiving Uncaught TypeError: Cannot set property 'innerHTML' of null when variable has value 未捕获的类型错误:无法设置未定义的属性“值” - JS - Uncaught TypeError: Cannot set property 'value' of undefined - JS 未捕获的TypeError:无法将属性“值”设置为null - Uncaught TypeError: Cannot set property 'value' of null 未捕获的类型错误:无法将属性“值”设置为 null - Uncaught TypeError: Cannot set property 'value' of null 未捕获的类型错误:无法将属性“值”设置为 null - Uncaught TypeError: Cannot set property 'value' of null 未捕获的类型错误:无法设置 null 的属性值 - uncaught TypeError: Cannot set property value of null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM