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

html-css013

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就是你当前要执行的js所抓获的节点,这样在js里就可以不用document.getElement之类的写法来抓获id,name或标签名,省去一些麻烦。一般用obj来代替。

<input type="button" id="tianjia" value="保 存" class="btn1" onClick="nullCheck(this)"/>

<script>

function nullCheck(obj)

{

......//这里写你所需功能的代码

}

</script>

with (object) { };

意思就是对object做一些事,方法体里面就是要对object做的事情,当然,只做一个操作的话,是体现不出好处的,with的目的,就是简化代码,比如:

with(document){

write("您好 !")

write("<br>这个文档的标题是 : \"" + title + "\".")

write("<br>这个文档的 URL 是: " + URL)

write("<br>现在您不用每次都写出 document 对象的前缀了 !")

},不用with的话,就得这样写:

document.write("您好 !")

document.write("<br>这个文档的标题是 : \"" + title + "\".")

document.write("<br>这个文档的 URL 是: " + URL)

document.write("<br>现在您不用每次都写出 document 对象的前缀了 !")

至于this,在这里指的就是这个form表单。