Home  >  Article  >  Web Front-end  >  htm calls JS code_Basic knowledge

htm calls JS code_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 19:16:36970browse
1. How to write the main page using JS to call Htm?
Write this code in the appropriate position between and :

src="js file name and path"
2. How to write a js file?
For example: write the content of head.js like this, convert the html in the main page into JS code, and use the JS statement "document.write" or "document.writeln" to output it.
It is more convenient to use software to automatically convert, such as: HTML to AnyCode, and store it in the corresponding js file.
Note:
If you use "HTML to AnyCode" to save the document, there will be a "/" symbol after the end of the file. Delete it manually. Otherwise, the main page will not display the call correctly.
If you copy the code directly, you need to remove "", leaving only "document" .writeln" output statement.
Attachment: document.write () and document.writeln () Differential
Document.write ()
// Write the contents of the content of the current editing position.
document.writeln()
//Write the content into the document and add a newline character. The current editing position is the starting position of the next line after the written content.
document.write () and document.writeln () are both JavaScript methods for writing to the client.
Writeln is output in line mode. Generally, there is no difference between the output effects of the two methods on the page. The difference between the two methods can only be seen when viewing the source code, unless it is output to pre or within an xmp element.
Copy code The code is as follows:

document.writeln("Baidu")
document .writeln("Baidu")
document.writeln("know")
document.writeln("know")
document.writeln("know")

Copy code The code is as follows:

document.write("
Baidu") <br>document .write("Baidu") <br>document.write("know") <br>document.write("know") <br>document.write("know
")

Today I tried the JS remote call of the classic download station and basically achieved the expected results.
It’s just that the tags that come with the Garlic system cannot be converted.

After consulting the reason, the customer service replied: "It cannot be called using js. Our tags are parsed and output through a scan when loading the page. If called in js, even if you escape it Even if the tag is output, it will not be parsed. ”

It should be noted that when converting html code with JS, it is best to only convert the content within the DIV placeholder, so that the position of the entire page can be fixed. Dislocation occurs.

In addition, I found that when using JS to call JS, "HTML to AnyCode" does not need to be modified after conversion, and it can be used directly.

Yahoo ads, after JS call, no special processing is required and can be used directly.
Google, haven’t tried it yet, will solve it later.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn