Some problems introduced by single quotation mark/double quotation mark and external JS in JS

Source: Internet
Author: User

Questions about the use of single and double quotes

Single and double quotes can be used in JavaScript, and they can be used in combination. However, as a rookie of me, but encountered some use of quotation marks.

<body><div style= "border:1px solid red; height:150px;width:150px; "onclick=" Alert ("Test");  id= "Test" >this is a test.</div></body>

Theoretically, clicking on this div will have a frame, but no matter how you click,Bullet BoxDon't appear, do not believe? Click to view the demo. Wrestling, there's no problem with the code, but a small place is changed, and the box is out.

<body><div style= "border:1px solid red; height:150px;width:150px; "onclick=" alert (' Test ');  id= "Test" >this is a test.</div></body>

Click to see the demo, I feel very strange, so I changed a small place, the box is gone

<body><div style= "border:1px solid red; height:150px;width:150px; "onclick= ' Alert (' Test ') '  id=" test ">this is a test.</div></body>

Click to see the demo, I am a little dizzy, in order to understand a little bit of change in a small place, the box has appeared

<body><div style= "border:1px solid red; height:150px;width:150px; "onclick=" Alert ("Test") '  id= "test" >this is a test.</div></body>

Click to view the demo.

PS: You can put the code in the editor, see the changes in the small place font color change!!!



Second, the problem of introducing external JS in

In a generic project, JS, CSS, and HTML are all separate, typically by introducing the SRC attribute of the corresponding element in

Html:

<pre name= "Code" class= "JavaScript" ><body><div style= "border:1px solid blue; height:150px;width:150px; "onclick=" test ();   id= "Test" >this is a test.</div></body>


Test.js

Window.onload=function () {<pre name= "code" class= "JavaScript" >function Test () {alert ("Test");}}


Click on the div without pop-up window, effect demo


Test.js file after modification

function test () {alert ("Test");}

Pop-up window appears, effect demonstration, you can also remove the div's onclick attribute, added in JS, modified as follows:

Html:

<body><div style= "border:1px solid blue; height:150px;width:150px; "   id= "Test" >this is a test.</div></body>

Modified Test.js

Window.onload=function () {var test = document.getElementById ("Test"), Test.onclick = function () {alert ("Test");}}

Effect Demo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.