In JavaScript, in order to perform different actions for different elements, you need to judge the elements that trigger the event in JavaScript, and then perform different actions.
Example:
Html
Copy Code code as follows:
<input type= ' button ' name= ' updatemetal ' value= ' modify ' onclick= ' Getmetalid (this) ' >
<input type= ' button ' name= ' deletemetal ' value= ' delete ' onclick= ' getmetalid (this) ' >
Javascript
Copy Code code as follows:
<script type= "Text/javascript" >
function Getmetalid (input) {
Metalid = Input.parentNode.parentNode.firstChild.innerHTML;
if (Input.getattribute ("value") = = ' Modify ') {
Damicsubmit (Metalid);
}else if (Input.getattribute ("value") = = ' Delete ') {
Damicsubmit2 (Metalid);
}
}
</script>
Getting the name and id attribute of input was unsuccessful, but value was OK, not knowing what the reason was.
Reference:
Copy Code code as follows:
var Obj=document.getelementbyid ("Div1"). getElementsByTagName ("textarea")
for (Var i=0;i<obj.length;i++)
{
if (obj[i].id== "AA")
{
Alert (Obj[i].innertext)
}
}