Home  >  Article  >  Web Front-end  >  javascript与jquery中的this关键字用法实例分析_javascript技巧

javascript与jquery中的this关键字用法实例分析_javascript技巧

WBOY
WBOYOriginal
2016-05-16 15:23:521398browse

本文实例分析了javascript与jquery中的this关键字用法。分享给大家供大家参考,具体如下:

this 表示当前的对象,这个当前对象可以是表单,

等任何元素

1.javascript中this的用法:

JS部分:

<script type="text/javascript">
 function chimg(obj){
  obj.src="./images/2.jpg";
 }
</script>

HTML部分:

复制代码 代码如下:
javascript与jquery中的this关键字用法实例分析_javascript技巧

2.jquery 中this的用法:

JS部分:

<script type="text/javascript">
  $(document).ready(function(){
   alert(this.src);
  })
</script>

HTML部分:

复制代码 代码如下:
javascript与jquery中的this关键字用法实例分析_javascript技巧

希望本文所述对大家JavaScript程序设计有所帮助。

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