


Explanation of the difference between the output content of document.write and writeln_Basic knowledge
document.write() //Write the content into the document, the current editing position is the last character of the written content
document.writeln() //Write the content into the document, and add a newline character, the current editing position The next line of the written content
document.write() and document.writeln are both JavaScript methods for writing to the client. writeln is output in line form, but it does not refer to the actual effect of the page. Line breaks, the difference between the two methods can only be seen when viewing the source code, unless it is output to a pre or xmp element
Test it:
[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
Run the above code, in In the newly opened window: View - Source File, you can see that writeln outputs
in line format. The difference in the actual effect is that the line break in the source code will cause a "space" in the actual effect. Compare the following examples to understand: If you need to introduce external Js, you need to refresh to execute
]
The input result is actually: 111 222 So in the application, using write will be more convenient than writeln, and will not produce unnecessary space effects, so my Html and Js online mutual conversion gadget [
http://www .jb51.net/tools/html-js.htm
] I specially changed the way most people use writeln on the Internet to write. I believe it will bring convenience to everyone.
[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
]
The difference between document.write() and document.writeln() Use js to write dynamic select
Solution:
Both are methods of JavaScript output to the client. Comparison shows The difference in writing is the abbreviation of ln--line. In other words, the writeln method outputs in lines, which is equivalent to adding a newline character after the ?winte? output.
Note: The document.write method can be used in two ways: using real-time scripts to create web page content during web page loading and using delayed scripts to create the content of this window or a new window. This method requires a string Parameter, which is the HTML content written to the window or frame. The string parameter can be a variable or an expression whose value is a string. The written content often contains HTML tags.
Remember, load the web page After that, the browser output stream will be automatically closed. After that, any document.write() method on the current web page will open a new output stream, which will clear the output content of the current web page (including any changes in the source document). and value). Therefore, if you want to replace the current web page with the HTML content generated by the script, you must concatenate the HTML content and assign it to a variable. Here, use document.write() to complete the writing operation. There is no need to clear the document and open a new one data flow, a document.write() call is OK.
Regarding the document.write() method, you also need to explain its related method document.close(). The script writes to the window (whether it is this window Or other windows) The output stream must be closed after writing the content. After the last document.write() method of the script. You must ensure that there is a document.close() method. If you do not do this, images and forms cannot be displayed. Moreover, later calls Any document.write() will only append the content to the web page, but will not clear the existing content and write new values
Specific steps:
1. Open a blank window.
window.open()
2. Use the write method to write code to the blank window.
document.write("Line1")
document.write("Line1")
3. Use the writeln method to write code to the blank window.
document.writeln("Line1")
document.writeln("Line2")
<script> with(window.open()){ document.write("百度") document.write("百度") document.writeln("知道") document.writeln("知道") document.writeln("知道") } </script><script> document.writeln("111") document.writeln("222") </script> The code is as follows:<script> document.write("<pre class="brush:php;toolbar:false">百度") document.write("百度") document.writeln("知道") document.writeln("知道") document.writeln("知道") </script><div class="codebody" id="code97054"> <br><script> <br>with(window.open()){ <br>document.write("Line1") <br>document.write("Line1") <br>document.writeln ("Line1") <br>document.writeln("Line2") <br>} <br></script> <br> </div> <br><br>Note: Both methods are only available when viewing the source You can only see the difference when looking at the code. <br>Special tip: Add the above code to the web page, and then view the source code of the pop-up window, you will see: <br><br>Line1Line1Line1 <br>Line2 <br><br>The page effect and source code are as follows picture. <br><br><img src="/static/imghw/default1.png" data-src="http://files.jb51.net/file_images/article/201402/20140221170111.jpg" class="lazy" alt="Explanation of the difference between the output content of document.write and writeln_Basic knowledge" ><br><br><br>Special Note<br><br>In general, there is generally no difference in the output effects of the two methods on the page (unless It is output to the pre or xmp element). <br><br><strong>2. document.write() writes html to the specified location <br></strong><br>When the page is initialized, it can be written correctly in the select box <br>But when it is called, it is written in the control Besides, I wonder if document.write() can change innerHTML or outerHTML to dynamically write HTML? And how to deal with the written HTML for display? <br><br> is as follows: <br><br><div class="codetitle"> <span><a style="CURSOR: pointer" data="78491" class="copybut" id="copybut78491" onclick="doCopy('code78491')"><u>Copy code </u></a></span> The code is as follows: </div> <div class="codebody" id="code78491"> <br>&lt ;html> <br><head></head> <br><script type="text/javascript"> <br>function creatOption(){ <br>for(i=0;i<5 ;i ) <BR>document.write("<option value='" i "'>" i "</option>"); <br>} <br>function openWrite(){ <br>var win=window.open(); <br>win.document.write("Line1"); <br>win.document.write("Line1"); <br>win.document.write("<input type ='text' value='1234567890' />"); <br>win.document.writeln("Line1"); <br>win.document.writeln("Line2"); <br>} <br> </script> <br><body> <br><select id="myselect" name="myselect"> <br><script language="javascript"> <br>creatOption(); <br></script> <br></select> <br><input type="button" value="Button" onclick="openWrite()"/> <br></body> <br></html> <br> </div> <br><br> Regarding retaining the format, test it: <script> document.write("<pre class="brush:php;toolbar:false">I don’t wrap lines in pre!") document.write("I will not wrap lines in pre!")document.writeln("I will wrap lines in pre!")document.writeln("I will wrap lines in pre!")document.writeln("I will wrap lines in pre Line breaks will occur in pre!</pre>") </script>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

The article discusses effective JavaScript debugging using browser developer tools, focusing on setting breakpoints, using the console, and analyzing performance.

The article explains how to use source maps to debug minified JavaScript by mapping it back to the original code. It discusses enabling source maps, setting breakpoints, and using tools like Chrome DevTools and Webpack.

This tutorial will explain how to create pie, ring, and bubble charts using Chart.js. Previously, we have learned four chart types of Chart.js: line chart and bar chart (tutorial 2), as well as radar chart and polar region chart (tutorial 3). Create pie and ring charts Pie charts and ring charts are ideal for showing the proportions of a whole that is divided into different parts. For example, a pie chart can be used to show the percentage of male lions, female lions and young lions in a safari, or the percentage of votes that different candidates receive in the election. Pie charts are only suitable for comparing single parameters or datasets. It should be noted that the pie chart cannot draw entities with zero value because the angle of the fan in the pie chart depends on the numerical size of the data point. This means any entity with zero proportion

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

Once you have mastered the entry-level TypeScript tutorial, you should be able to write your own code in an IDE that supports TypeScript and compile it into JavaScript. This tutorial will dive into various data types in TypeScript. JavaScript has seven data types: Null, Undefined, Boolean, Number, String, Symbol (introduced by ES6) and Object. TypeScript defines more types on this basis, and this tutorial will cover all of them in detail. Null data type Like JavaScript, null in TypeScript
