Html function 传入 this 参数 和 function中 with() 问题

html-css09

Html function 传入 this 参数 和 function中 with() 问题,第1张

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表单。

你好!!

使用jQuery么?

//jQuery的方式:

function A(temp){

    alert(   $(temp).parent().html()   )

} //javascript方式

function A(temp){

    alert( temp.parentNode.innerHTML )

}

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="按我测试"/>