Home > Web Front-end > JS Tutorial > The difference between $('#') and $('#'+xx) in jquery

The difference between $('#') and $('#'+xx) in jquery

青灯夜游
Release: 2020-09-07 10:22:24
forward
2554 people have browsed it

The following article will introduce to you the difference between $("#") and $("#" xx) in jquery. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

The difference between $('#') and $('#'+xx) in jquery

Related recommendations: "jQuery Video Tutorial"

$("#") refers to selection The selector selects an element with an id, such as You can use $("#id").val() to get the corresponding data value. If there is a plus sign in it, there is usually a variable. When encapsulating the function Commonly used, for example: the following small demo

<script src="jquery-1.8.3.js"></script>
 <body>
  <input type="text" value="a1" id="a1"><br/>
  <input type="text" value="a2" id="a2"><br/>
  <input type="text" value="a3" id="a3"><br/>
  <input type="text" value="a4" id="a4"><br/>
  <input type="text" value="a5" id="a5"><br/>
  <input type="button" value="点击测试" οnclick="test_()">
 </body>
 <script>
	function test_() {
		var a1=$("#a1").val();
		alert(a1);
		for(var i=1;i<=5;i++) {
		//这里+只是一个连接的作用,总得来说就是jquery的选择器,没有区别的说法
			var a=$("#a"+i).val();
			alert(a);
		}
	}
 </script>
</html>
Copy after login

The + here is just a connection function. Generally speaking, it is the selector of jquery. There is no difference.

For more programming-related knowledge, please visit : Programming Teaching! !

The above is the detailed content of The difference between $('#') and $('#'+xx) in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template