Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Is innerhtml the jquery method?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces whether innerhtml is a jquery method, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.

Innerhtml is not a jquery method, but a HTML DOM attribute, that is, a JavaScript attribute; this attribute is used to set or return the content of the element (including child elements), and the syntax "element object [xss_clean] =" content value "or" element object [xss_clean] ".

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

Innerhtml is not a jquery method, but a HTML DOM property that sets or returns the contents of an element.

The innerHTML property sets or returns the HTML between the opening and closing tags of a tag element.

Syntax:

/ / set element content object [XSS _ clean] = text// return element content object [XSS _ clean]

The following is an example of the use of the innerHTML property.

When the input is not empty, the text entered by the user will be displayed line by line in the div together with the label in front of the text box each time it is sent, and the contents of the text box will be cleared. If the input is empty, a warning dialog box prompts the user.

Use the innerHTML attribute to set the div element content div {width:240px; height:200px; background:#f1f1f1; border:1px solid # 333; padding:10px;} _ window.onload = function () {var oDiv = document.getElementById ('div1'); var oSpan = document.getElementByldCspan1'); var oText = document.getElementById (' text1'); var oBtn = document.getElementById ('btn1.') OBtn.onclick = function () {if (! oText.value.match (/ slots /)) {/ / use the regular expression to determine whether the input is an empty character / / take the label in front of the text box, the entered text, the newline tag and the original content of div as the contents of the div element oDiv [XSS _ clean] + = oSpann [XSS _ clean] + oText.value +'

'; oText.value =''; / / clear the text box} else {alert ("Please enter the information!);};}; after sending the message:

The if () judgment statement in the above code uses a regular expression to determine whether the input is an empty character. In the code, oSpan[ XSS _ clean] and oDiv [XSS _ clean] are used to get the contents of the span element and the div element respectively, and then, through oDiv [XSS _ clean], the contents of the span element and the div element, the input of the text box and the newline tag are set together as the content of the div element.

Note: oDiv [XSS _ clean] + = oSpann [XSS _ clean] + oText.value is equivalent to oDiv [XSS _ clean] = oDiv [XSS _ clean] + oSpan[ XSS _ clean] + oText.value.

The following figure shows the result of entering two lines of text in the text box and clicking the send button:

Thank you for reading this article carefully. I hope the article "innerhtml is the jquery method" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report