The difference between getElementsByName and getElementById
GetElementsByName gets an array
getElementById gets a number
function sum(n, m) {
var summary = 0;
var a = document.getElementsByName(n.toString());
for (var i = 0; i < a.length; i++) {
summary = summary + Number(a[i].value);
}
//1
var b = document.getElementById(m);
b.value = summary;
//2
var f = document.getElementsByName(m);
f[0].value = summary;
}
Read More:
- JavaScript summary: the difference between typeof and instanceof, and Object.prototype.toString() method
- The difference between “?” and “?:” introduced by php7
- The difference between LSTM and Gru
- The difference between problem and observables
- Parsing the difference between “R” and “RB” patterns of text files (Python)
- C#: Analysis of the difference between write() and writeline()
- The difference of. Pt,. PTH,. Pkl and the way to save the model
- The difference between classnotfoundexception and NoClassDefFoundError
- The difference and usage of insmod and modprobe
- Difference between vs code user and system version
- The difference between sleep() and wait() in Java
- The usage and difference of atoi() and stoi() functions in C + +
- Difference between isempty method and isblank method in stringutils
- The difference between onready or $() and onload
- The difference between hive and relational database
- The tutorial and difference of glew, glfw, glad and freeglut
- Node.js Medium package.json The difference between devdependences and dependencies
- The difference of four kinds of integer function (fix floor ceil round) in MATLAB
- Python json.dumps () json.dump The difference between ()
- In C + + cin.getline The difference between () and getline () functions