当前位置:网站首页>Learn to punch in today
Learn to punch in today
2022-07-03 14:09:00 【VIXeH】
jQuery
- Learned two ways of traversal
// The first main traversal dom object
$('div').each(function (index, domEle) {
console.log(index);
// The second parameter is dom object , First convert
console.log($(domEle));
})
// The second traversal method , It's mainly used to process data , You can traverse any object , Array etc.
$.each($('div'), function (i, element) {
// The first parameter is the index , The second is the corresponding value , similar java Of foreach
})
- How to set and get properties
about style In the properties of the :
Return property value
$(“p”).css(“ Property name ”);
Setting property values
$(“p”).css(“ Property name ”,“ Property value ”);
Set up multiple
$(“p”).css({“background-color”:“yellow”,“font-size”:“200%”});
For the attributes of the tag :
Returns the value of the property :
$(selector).prop(property)
Set properties and values :
$(selector).prop(property,value)
Use functions to set properties and values :
$(selector).prop(property,function(index,currentvalue))
Set multiple properties and values :
$(selector).prop({property:value, property:value,…})
Be careful
prop() Method to set or return the properties and values of the selected element .
When this method is used to return a property value , Then returns the value of the first matching element .
When this method is used to set the property value , Set one or more attributes for the set of matching elements / It's worth it .
Be careful :prop() Method should be used to retrieve property values , for example DOM attribute ( Such as selectedIndex, tagName, nodeName, nodeType, ownerDocument, defaultChecked, and defaultSelected).
For custom properties
Returns the value of the property :
$(selector).attr(attribute)
Set properties and values :
$(selector).attr(attribute,value)
Use functions to set properties and values :
$(selector).attr(attribute,function(index,currentvalue))
Set multiple properties and values :
$(selector).attr({attribute:value, attribute:value,…})
prop and attr You can get the attribute value , but prop We don't scan the source code to get it, but according to the information of the page .
- About new elements
With jquery Way to create :
var txt2=$("<p></p>")
Or by html()
How to add elements :
append() - In the selected element Inside Insert at the end of , Father and son
prepend() - In the selected element Inside Insert at the beginning of , Father and son
after() - In the selected element after Insert content , Brotherhood
before() - In the selected element Before Insert content , Brotherhood
Delete element mode :
remove() - Delete selected elements ( And its subelements )
empty() - Remove child elements from selected elements
边栏推荐
- Solve the problem of dormitory router campus network sharing login
- How to delete an attribute or method of an object
- QT learning 23 layout manager (II)
- Go 1.16.4: manage third-party libraries with Mod
- Redis:Redis的数据结构、key的操作命令
- FPGA测试方法以Mentor工具为例
- Exercise 8-7 string sorting
- TS code automatically generates JS
- Vite project commissioning
- Canvas utility library fabric JS user manual
猜你喜欢

Redis:字符串類型數據的操作命令

JS input number and standard digit number are compared. The problem of adding 0 to 0

Article content typesetting and code highlighting

FPGA测试方法以Mentor工具为例

Exercise 6-1 classify and count the number of characters

Redis: redis data structure and key operation commands

Exercise 6-2 using functions to sum special A-string sequences

核酸修饰的金属有机框架药物载体|PCN-223金属有机骨架包载Ad金刚烷|ZIF-8包裹阿霉素(DOX)

Summary of common error reporting problems and positioning methods of thrift

Vite project commissioning
随机推荐
Solution to failure or slow downloading of electron when electron uses electron builder to package
Use and design of Muduo buffer class
项目协作的进度如何推进| 社区征文
How to promote the progress of project collaboration | community essay solicitation
从零开始的基于百度大脑EasyData的多人协同数据标注
Go language web development series 26: Gin framework: demonstrates the execution sequence of code when there are multiple middleware
RocksDB LRUCache
Current situation, analysis and prediction of information and innovation industry
[acnoi2022] guess numbers
Common mixins
Common plug-ins for vite project development
Go 1.16.4: manage third-party libraries with Mod
JS shift operators (< <,> > and > > >)
Uio-66-cooh loaded bendamostine | hydroxyapatite (HA) coated MIL-53 (FE) nanoparticles | baicalin loaded manganese based metal organic skeleton material
Print. JS -- web page file printing
Too many files with unapproved license
QT learning 21 standard dialog box in QT (Part 2)
JS first summary
如何使用lxml判断网站公告是否更新
Exercise 9-1 time conversion