Five output modes commonly used in JS

  • 2021-06-28 10:09:01
  • OfStack

There's not much rubbish. I'll work for you directly. The details are as follows:

1. alert ("what to output");

- > Pop up a dialog box in your browser and show what you want to output

- > alert is all about converting the output to a string and then to the output

2. document.write ("Content to be output");

- > Show the output directly on the page

3. console.log ("Content to be Output");

- > Output in console

4. value - > Assigning content to text boxes (form elements)

- > Gets the contents of a text box (form element)

document.getElementById ("search"). value = "What to add to #search this text box";

5. innerHTML/innerText - > Assign content to labels other than form elements

document.getElementById ("div1"). innerHTML = "Okay, okay";
document.getElementById ("div1"). innerText = "Well, well";

- > Differences between innerHTML and innerText

1) When innerHTML assigns a value, if it encounters a valid HTML tag and treats it as a real tag, the tag can play its own role.

innerText assigns values whether labels are text or not, so what you see is text, and labels do not play their own role.

(innerHTML recognizes HTML tags when assigning values, but innerText does not)

2) In some Firefox browsers, innerText is not supported, while innerHTML is supported by all browsers


Related articles: