当前位置:网站首页>JS related knowledge
JS related knowledge
2022-07-24 00:50:00 【Hua Weiyun】
1.$(function() {})
$(function() {}) yes jquery There is a way of writing , Similar to the original js Medium DOMContentLoaded event . He was $(document).ready(function() Abbreviation .
When is this function executed ?
He is in DOM It is executed after loading , That is, all the pages html label ( Including pictures, etc ) All loaded , The browser has responded , all dom The tree is all displayed on the browser interface ( It's all kinds of element labels ), Everything is all set. ( The picture , These static resources such as audio and video have not been loaded ) This function starts to execute .
2.JSON.stringify()
JSON.stringify() Method is used to JavaScript Value to JSON character string . His grammar is JSON.stringify(value[, replacer[, space]]), among value For the data that needs to be transformed ;replacer Optional. . The function or array used to convert the result . If replacer For the function , be JSON.stringify This function will be called , And pass in the key and value of each member . Use the return value instead of the original value . If this function returns undefined, Then exclude members . The key of the root object is an empty string :"". If replacer Is an array , Only the members with key values in the array are converted . Members are converted in the same order as keys in the array ;space It's also an option , Is to add indentation to the text 、 Space and newline , If space It's a number , The return value text is indented by a specified number of spaces at each level , If space Greater than 10, The text is indented 10 A space .space You can also use non numbers , Such as :\t.
We usually use JSON.stringify(value) To quickly convert data into json character string .
3.JSON.parse()
JSON.parse() Method to convert data to JavaScript object . His grammar is JSON.parse(text[, reviver]), among text It's a required option , He must be an effective JSON character string , If it is not, it will report an error ;reviver Optional. , Is a function of the conversion result , This function will be called for each member of the object to be converted .
4.JS Get information about the current web page
stay WEB In development , It's often used javascript To get the url Website information , Here are the small chestnuts for each part
Let's take a chestnut URL= http://test.com/testPath?parm=123
4.1 window.location.href Get the entire URL For the string
var tem= window.location.href; return :http://test.com/testPath?parm=123
4.2 window.location.protocol obtain URL Part of the agreement
var tem= window.location.protocol; return :http:
4.3 window.location.host obtain URL The host part of
var tem= window.location.host; return :test.com
4.4 window.location.port To obtain and URL Associated port number
var tem= window.location.port; return : Null character ( This is because the default 80 port ( Even if you add it manually :80), So the return value is not the default 80 It's an empty character )
4.5 window.location.pathname To obtain and URL The path part of
var tem= window.location.pathname; return :/testPath
4.6 window.location.search obtain href The part of the attribute that follows the question mark
var tem= window.location.search; return :?parm=123
4.7 window.location.hash obtain href Attribute in "#" Later parameters
var tem= window.location.hash; return : Null character
边栏推荐
- Résumé du websocket minier
- Classic example of C language - find the minimum number of banknotes
- Xilinx FPGA one way clock input two PLLs
- Classic example of C language - convert the input two digits into English
- Notes and Reflections on the red dust of the sky (V) strong culture and weak culture
- What is promise? What are the benefits of promise
- JS drag and drop element
- MySQL data query (select)
- Blockbuster | certik: Web3.0 industry safety report release in the second quarter of 2022 (PDF download link attached)
- Robot dog back submachine gun shooting video fire, netizens shivering: stoooooooopppp!
猜你喜欢

Customize an object

测试小码农也有大目标,最新BAT大厂面试题大总结(持续更新中...)

QT入门篇(2.1初入QT的开始第一个程序)

The way to access global variables in multi-source file mode (extern usage)

freemarker

Docker pulls the redis image and runs it

Method of C language annotation
![[video game training] non contact object size and shape measurement 2020 video game G](/img/b7/d70a702e52062e38176b589eb15415.jpg)
[video game training] non contact object size and shape measurement 2020 video game G

Blockbuster | certik: Web3.0 industry safety report release in the second quarter of 2022 (PDF download link attached)

How can dbcontext support the migration of different databases in efcore advanced SaaS system
随机推荐
这是一道大水题
MySQL table field quantity limit and row size limit
ES6 combines multiple class methods
The way to access global variables in multi-source file mode (extern usage)
【LeetCode第 83 场双周赛】
Flutter | firstwhere error reporting
Table custom table encapsulation
Development of main applet for business card traffic near the map
【数据挖掘工程师-笔试】2022年海尔 公司
C language writing specification
《天幕红尘》笔记与思考(六)因缺而需
How to improve data quality
Tutorial on principles and applications of database system (043) -- MySQL query (V): Sorting Query Results
MariaDB database upgrade version
PostgreSQL snapshot optimization globalvis new system analysis (greatly enhanced performance)
项目场景:nvidia-smi Unable to datemine the device handle for GPU 0000:01:00.0: Unknow Error
Unity metaverse (I). Ready player me & blender customize your Avatar
Design details related to sap e-commerce cloud Spartacus UI store
Accelerating matrix vector multiplication of special matrices with FFT
【电赛训练】非接触物体尺寸形态测量 2020年电赛G题