The problem is this
var id=document.getElementById(ele);
var cls=document.getElementsByClassName(ele);
var tag=document.getElementsByTagName(ele)
Now we need to determine what type of ele it is and write it like this, that is,
For example, if I enter a label 'a', it means the label, #a means id, and .a means class to perform the corresponding operation
<body>
<p id="app">
测试1
</p>
<p>测试2</p>
<span class="span">测试3</span>
<script>
window.onload=function () {
function getreg(ele) {
var id=document.getElementById(ele);
var cls=document.getElementsByClassName(ele);
var tag=document.getElementsByTagName(ele)
alert(cls.getAttributeNode('p'))
}
getreg('app')
}
</script>
</body>
The code is like this
Because there may be at least one element in the page
If you simply want to get the element, you can use
You must use the original idea to determine the input type