In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
In this article Xiaobian detailed introduction of "javascript how to add a paragraph", the content is detailed, the steps are clear, the details are handled properly, I hope this "javascript how to add a paragraph" article can help you solve your doubts, the following slowly deepen with the editor's ideas, let's learn new knowledge.
Javascript add a paragraph method: 1, through the "[xss_clean]" method to insert html paragraph; 2, through the DOM method to insert html paragraph.
This article operating environment: windows7 system, javascript1.8.5 version, DELL G3 computer
How does javascript add a paragraph?
JavaScript insert html paragraph method
Traditional methods:
[xss_clean] method
You can insert directly through the script tag where you need to insert it.
[xss_clean] ("
This is inserted.
")
Or move to an external function
InsertParagraph ("This is inserted");... function insertParagraph (text) {var str = "
"+ text+"
"[xss_clean] (str)}
But it's not a good idea to mix JavaScript code with HTML code anyway.
InnerHTML attribute
InnerHTML can either write the html code or read the html code under the selected node. The innerHTML insertion directly replaces everything below the selected node.
This will be overwritten.
_ window.onload = function () {var insertDiv = document.getElementById ("insert") alert (insertDiv [XSS _ clean]) insertDiv [XSS _ clean] = "
This is inserted.
"}
DOM method
CreateElement method: document.createElement (nodeName)
To create a new element, the following code creates a p element.
Var insertElement = document.createElement ("p") appendChild method: parent.appendChild (child)
Make this node a child of the target node
Var insertElement = document.createElement ("p"); document.getElementById ("insert") .appendChild (insertElement); creatTextNode method: document.createTextNode (text)
Similar to the createElement method, but creates a text node
Var txt = document.createTextNode ("New insert text."); insertElement.appendChild (txt); insertBefore method: parentElement.insertBefore (newElement,targetElement)
Insert a new element in front of an existing element. Where parentElement is the parent of the target element, newElement is the element you want to insert, and targetElement you want to insert the element in front of it.
Var newInsertElement = document.createElement ("p"); insertDiv.insertBefore (newInsertElement,insertDiv); after reading this, the article "how to add a paragraph to javascript" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it to understand it. If you want to know more about related articles, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.