html的标签中的this应该如何使用

html-css010

html的标签中的this应该如何使用,第1张

<html> 

<head> 

<script type="text/javascript"> 

function showHint(str){ 

alert(str)  

</script> 

</head> 

<body> 

<input type="text" onkeyup="showHint(this.value)"/> <!--此处,在html标签中的this代表的是此标签--> 

</body> 

</html>

this是指本元素

每一个HTML标签,都会在DOM树下产生一个元素节点,这个this是写在哪个标签内,那么show函数里面的参数就是哪个标签所产生的元素的id,如

<input type="button" id="我是button1" onclick="alert(this.id)" value="按我测试"/>

<input type="button" id="我是button2" onclick="alert(this.id)" value="按我测试"/>