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