当前位置:网站首页>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
边栏推荐
- JS Part III
- Solution to failure or slow downloading of electron when electron uses electron builder to package
- JVM垃圾回收机
- [combinatorics] permutation and combination (two counting principles, examples of set permutation | examples of set permutation and circle permutation)
- Use and design of Muduo buffer class
- 八大排序
- Formation of mil-100 (FE) coated small molecule aspirin [email protected] (FE) | glycyrrhetinic acid modified metal organ
- QT learning 20 standard dialog box in QT (middle)
- Multi person collaborative data annotation based on Baidu brain easydata from scratch
- Fabric. JS document
猜你喜欢
Conversion function and explicit
信创产业现状、分析与预测
全局事件总线
Qt学习18 登录对话框实例分析
jvm-类加载
Scroll detection, so that the content in the lower right corner is not displayed at the top of the page, but is displayed as the mouse slides
Use and design of Muduo buffer class
Go language web development series 29: Gin framework uses gin contrib / sessions library to manage sessions (based on cookies)
Implementation of Muduo accept connection, disconnection and sending data
28: Chapter 3: develop Passport Service: 11: define attributes in the configuration file, and then obtain them in the code;
随机推荐
Current situation, analysis and prediction of information and innovation industry
Go language web development series 28: solve cross domain access of CORS with gin contrib / CORS
JVM family - overview, program counter day1-1
js 2023. String pair equal to the target string after connection
Spring cup eight school league
JS input number and standard digit number are compared. The problem of adding 0 to 0
Formation of mil-100 (FE) coated small molecule aspirin [email protected] (FE) | glycyrrhetinic acid modified metal organ
Function calling convention
Scroll detection, so that the content in the lower right corner is not displayed at the top of the page, but is displayed as the mouse slides
可编程逻辑器件软件测试
Comprehensive case of MySQL data addition, deletion, modification and query
Toast UI editor (editor allows you to edit your markup document using text or WYSIWYG, with syntax highlighting, scrolling synchronization, real-time preview and chart functions.)
Qt学习20 Qt 中的标准对话框(中)
Qt学习21 Qt 中的标准对话框(下)
Use vscode to view hex or UTF-8 codes
Uniapp skills - dom display and hiding
TS code automatically generates JS
[acnoi2022] guess numbers
Reflection -- basic usage
Duet date picker (time plug-in that can manually enter the date)