Home >Web Front-end >JS Tutorial >Example analysis of this keyword usage in javascript and jquery_javascript skills

Example analysis of this keyword usage in javascript and jquery_javascript skills

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

This article analyzes the usage of this keyword in javascript and jquery through examples. Share it with everyone for your reference, the details are as follows:

this represents the current object, which can be a form, e388a4556c0f65e1904146cc1a846bee and other elements

1. Usage of this in javascript:

JS part:

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

HTML part:

Copy code The code is as follows:
ef783d07204eee4e86396a81d92c5dca

2. Usage of this in jquery:

JS part:

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

HTML part:

Copy code The code is as follows:
78ee90a7351db3376fa17256f9b94c9c

I hope this article will be helpful to everyone in JavaScript programming.

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