Home  >  Article  >  Web Front-end  >  javascript动态判断html元素并执行不同的操作_javascript技巧

javascript动态判断html元素并执行不同的操作_javascript技巧

WBOY
WBOYOriginal
2016-05-16 16:44:26875browse

在javascript中为了针对不同的元素执行不同的操作,需要在javascript中对触发事件的元素进行判断,然后执行不同的操作。

例子:

html

复制代码 代码如下:




javascript
复制代码 代码如下:



获取input的name和id属性都不成功,但是value却是可以的,不知道是什么原因。

参考:
复制代码 代码如下:

var obj=document.getElementById("div1").getElementsByTagName("textarea")
for(var i=0;i{
if(obj[i].id=="aa")
{
alert(obj[i].innerText)
}
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn