当前位置:网站首页>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
边栏推荐
- 项目场景:nvidia-smi Unable to datemine the device handle for GPU 0000:01:00.0: Unknow Error
- The most basic code interpretation of C language
- Redis | very important Middleware
- [low code] limitations of low code development
- Redis master-slave synchronization mechanism
- vim常用命令
- MySQL client to server character set conversion
- Tutorial on the principle and application of database system (046) -- MySQL query (VIII): group by
- How to improve data quality
- Classic examples of C language - adding two scores
猜你喜欢

Easy gene | target gene DNA methylation sequencing (target BS)

数仓数据指标和标签体系区别

Detailed explanation of data warehouse standard -2022

Classic example of C language - commodity inspection code

Prometheus+node exporter+grafana monitoring server system resources

Memory forensics nssctf otterctf 2018 (replay)

Table custom table encapsulation

Distributed cap principle

How to use mitmproxy to get data return in automated testing?

Robot dog back submachine gun shooting video fire, netizens shivering: stoooooooopppp!
随机推荐
This is a big problem
Don't let Fujin Yibo see this
Redis | very important Middleware
High number_ Chapter 1 space analytic geometry and vector algebra__ Two point distance
mysql 分支语句case报错
The postman test interface has 404 or 500 errors when the URL is configured correctly
What is the function of the select... For UPDATE statement? Can you lock tables or rows?
JS determines whether the element scrolls to the top
PostgreSQL snapshot optimization globalvis new system analysis (greatly enhanced performance)
MySQL data query (select)
Notes and Reflections on the red dust of the sky (V) strong culture and weak culture
Database connection pool & dbutils
Docker pulls the redis image and runs it
XXL job realizes the code parsing of email sending warnings (line by line code interpretation)
Image processing: Generation 3 × Window of 3
Customize an object
vim常用命令
SAP 电商云 Spartacus UI Store 相关的设计明细
Bert article translation
js的相关知识