Home > Web Front-end > JS Tutorial > body text

About Jquery getting the properties and values ​​of objects

黄舟
Release: 2017-03-01 14:39:58
Original
1566 people have browsed it

1. Common methods for obtaining objects


##$("*") means getting all objects Generally not used)

$("#XXX") 'Get the element object with id=XXX (Commonly used)

##$(".XXX") 'Get the element object of class=XXX(commonly used)

$("p") ' Tag selector selects all p elements (commonly used) ##$("input[name='uname']") Get The element object with name='

uname

' in the input tag (commonly used) such as:

self.find("input[name='complany']").css('border','#FFB240 1px solid');
self.find("textarea[name='messcont']").css('border','#FFB240 1px solid');		
Copy after login

The above selection method can be used in combination with

space and greater than sign>, plus sign+ and tilde~

. For usage rules, you can refer to here (http://www.php. cn/) In this blog post, I forgot to add the use of comma combination. Here is a case of using comma combination If you want to get p with class message, the code is as follows:

<p class="message">
gegrew
</p>
<span class="message">ageaw</span>

<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
	console.log($(".message,p").html()) ;
</script>
Copy after login



##2. Other object acquisition methods

$("Element[attribute = 'ceshi']") obtains all certain attributes as ceshi

's element

$("Element[attribute != 'ceshi']") Gets all elements with a certain attribute that is not
ceshi$("Element[attribute ^= 'ceshi']") Gets all elements that have an attribute that does not start with
ceshi$("Element[attribute *='ceshi']" 'Get all elements
## with an attribute starting with ceshi #


<span class="message" src="hello">hello</span>
<span class="message" src="byebye">byebye</span>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
	console.log($("span[src =&#39;hello&#39;]").html()) ;
</script>
Copy after login



3、获取对象的属性

$("Element").attr(key)  获取某一个元素的属性

$("Element").attr(key,value)  给某一个元素设置属性

 以上就是关于Jquery获取对象的属性与值的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!


Related labels:
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!