[英]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.