The program code is:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Visit the Dangdang shopping cart page node</title>
<link type="text/css" rel="stylesheet" href="css/cartStyle.css" />
</head>
<body>
<div class="content">
<div class="logo">
<img src="images/dd_logo.jpg"><span onclick="close_plan();">close</span>
</div>
<div class="cartList" id="cartList">
<ul>
<li>¥<input type="text" name="price" value="21.90"></li>
<li><input type="button" name="minus" value="-" onclick="minus(0);"><input type="text" name="amount" value="1"><input type="button" name="plus" value="+" onclick="plus(0);"></li>
<li id="price0">¥21.90</li>
<li><p onclick="collection();">add</p><p onclick="del();">del</p></li>
</ul>
<ul>
<li>¥<input type="text" name="price" value="24.00"></li>
<li><input type="button" name="minus" value="-" onclick="minus(1);"><input type="text" name="amount" value="1"><input type="button" name="plus" value="+" onclick="plus(1);"></li>
<li id="price1">¥24.00</li>
<li><p onclick="collection();">add</p><p onclick="del();">del</p></li>
</ul>
<ol>
<li id="totalPrice"> </li>
<li><span onclick="accounts()">payout</span></li>
</ol>
</div>
<div id="money"></div>
</div>
<script type="text/javascript" src="js/shopping.js">
</script>
<script type="text/javascript">
function accounts(){
var num1=document.getElementById("cartList").firstChild.lastChild.previoustSibling.innerHTML;
var num2=document.getElementById("cartList").firstChild.nextSibling.lastChild.previousSibling.innerHTML;
var num3=document.getElementById("totalPrice").innerHTML;
var num4="Information about your current purchase is as follows:<br/>White Rock:White says: "+num1+"<br/>Island Bookstore: "+num2+"<br/>Total items:"+num3;
document.getElementById("money").innerHTML=num4;
}
</script>
</body>
</html>
Display error:
Uncaught TypeError: Cannot read property 'previoustSibling' of null
at accounts (shopping.html:39)
at HTMLSpanElement.onclick (shopping.html:29)
Error reason: unable to read space
Solution:
add element to the get node in function accounts()
The correct function code is:
function accounts(){
var num1=document.getElementById("cartList").firstElementChild.lastElementChild.previousElementSibling.innerHTML;
var num2=document.getElementById("cartList").firstElementChild.nextElementSibling.lastElementChild.previousElementSibling.innerHTML;
var num3=document.getElementById("totalPrice").innerHTML;
var num4="Information about your current purchase is as follows:<br/>White Rock:White says: "+num1+"<br/>Island Bookstore: "+num2+"<br/>Total items:"+num3;
document.getElementById("money").innerHTML=num4;
}
Read More:
- Method to solve uncaught typeerror: cannot set property ‘onclick’ of null error
- [Solved] Uni.createintersectionobserver Error: Uncaught TypeError: Cannot read property ‘bottom’ of null
- [Solved] JS Error: Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML‘)
- [Solved] electron Error: Uncaught TypeError: Cannot read property ‘BrowserWindow‘ of undefined
- [Solved] Error in callback for watcher “value“: “TypeError: Cannot read property ‘level‘ of null“
- [Solved] vue.esm.js?efeb:591 [Vue warn]: Error in event handler for “click“: “TypeError: Cannot read property
- [Solved] Binding onclick event in JS: for loop: error uncaught typeerror: cannot set properties of undefined (setting ‘classname’)
- [Solved] NPM err! Cannot read property ‘parent’ of null npm ERR! A complete log of this run can be found in: npm ERR!
- [Solved] Echarts Error: TypeError: Cannot read properties of null (reading getAttribute )
- Uni-app Error when assigning a value to a component: [system] TypeError: Cannot read property ‘name‘ of undefined
- [Solved] TYPEERROR: CANNOT READ PROPERTY ‘REDUCE‘ OF UNDEFINED
- About JS error uncaught syntax error: invalid shorthand property initializer
- [Solved] Vue Error: TypeError: Cannot read property ‘end‘ of undefined
- Echarts Partially introduced error: TypeError: Cannot read property ‘findAxisModel’ of undefined
- [Solved] Syntax Error: TypeError: Cannot read property ‘parseComponent‘ of undefined
- [Solved] Syntax Error: TypeError: Cannot read property ‘parseComponent‘ of undefined
- [Solved] Vue3 Import element UI error: Uncaught TypeError: Cannot read properties of underfined…
- [Solved] Install The Latest Version of Jest Error: TypeError: Cannot read property ‘instrument‘ of undefined
- [Solved] react Chrome Browser Error: Uncaught TypeError: Cannot read properties of undefined (reading ‘forEach‘)
- [Solved] Element form method resetfields() error: vue.runtime.esm.js?2b0e:1888 TypeError: Cannot read properties of undefined (reading ‘indexOf’)