Javascript dynamically judges HTML elements and performs different actions
- 2020-03-30 03:23:39
- OfStack
In javascript, in order to perform different operations on different elements, you need to judge the element that triggers the event in javascript and then perform different operations.
Example:
HTML
javascript
The name and id attributes of input were not successfully obtained, but the value was ok. I don't know why.
Reference:
Example:
HTML
<input type='button' name = 'updatemetal' value=' Modify the ' onclick='getmetalid(this)'>
<input type='button' name = 'deletemetal' value=' delete ' onclick='getmetalid(this)'>
javascript
<script type="text/javascript">
function getmetalid(input) {
metalid = input.parentNode.parentNode.firstChild.innerHTML;
if(input.getAttribute("value") == ' Modify the '){
damicsubmit(metalid);
}else if(input.getAttribute("value") == ' delete '){
damicsubmit2(metalid);
}
}
</script>
The name and id attributes of input were not successfully obtained, but the value was ok. I don't know why.
Reference:
var obj=document.getElementById("div1").getElementsByTagName("textarea")
for(var i=0;i<obj.length;i++)
{
if(obj[i].id=="aa")
{
alert(obj[i].innerText)
}
}