Get the App
SLTechnology News&Howtos  ›  Development  › 

How does JavaScript change HTML style

Shulou Source: shulou.com Published: 2022-06-01 04:19:02 09月22日 Update

Most people do not understand the knowledge points of this article "JavaScript how to change HTML style", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "JavaScript how to change HTML style" article.

JavaScript: changing HTML styl

Changing the style of the HTML element is a variant that changes the HTML attribute.

Example

X=document.getElementById ("demo") / / find the element

X.style. Color = "# ff0000"; / / change the style

JavaScript: validating input

JavaScript is often used to validate a user's input.

Example

IfisNaN (x) {

Alert ("not number")

}

The above examples are just ordinary verification. If you want to use them in a production environment, you need to make a strict judgment. If you enter a space or a consecutive space isNaN, you can't tell it out. Rules can be added to determine:

Example

If (isNaN (x) | | x.replace (/ (^\ s*)) | (\ sroom$) / g, ") = =") {

Alert ("not number")

}

The above is about the content of this article on "how to change the HTML style of JavaScript". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Tags: Styles content instances input validation elements numbers articles knowledge spaces articles ordinary value variants but for the most part attributes more rules Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia macOS Redmi Huawei Shulou Technology