>>
Site Map
>>
Forums
>>
JavaScript_HTML
Forum module - topics in forum:
JavaScript_HTML - tìm hiểu và trao đỏi các mã java để làm trang web bạn sinh động hơn, các thủ thuật code html css
External Javascript Files - sử dụng file từ ben ngoài
External Javascript Files - sử dụng file từ ben ngoài
Having already dicussed placing Javascript in the head and body of your HTML document, let us now explore the third possible location, an external file. If you have ever used external CSS this lesson will be a cinch.
Importing an External Javascript File
Importing an external file is relatively painless. First the file you are importing must be valid Javascript, and only Javascript. Second, the file must have the extension ".js". Lastly, you must know the location of the file.
Let us assume we have a file "myjs.js" that contains a one line Hello World alert function. Also, let us assume that the file is the same directory as our HTML file we are going to code up. To import the file you would do the following in your HTML document.
HTML & JavaScript Code:
| Code: : |
<html>
<head>
<script src="myjs.js">
</script>
</head>
<body>
<input type="button" onclick="popup()" value="Click Me!">
</body>
</html> |
Great Javascript Repositories
There is a ton of great stuff you can do with Javascript, if you know how to code like Paul Allen and Bill Gates, but for the rest of us it is nice to get incredible Javascript tools without having to write them ourselves. Below are some of the better Javascript resources on the web these days.
* JavaFile.com
* Java-Scripts.com
* Drop Down Javascirpt Menus
External File Tips & Recap
* Use external Javascript files when you want to use the same script on many pages, but don't want to have to rewrite the code on every page!
* Use external Javascript files for including both types of scripts! The type that you place in the head (functions) and the type you place in the body (scripts you want to run when the page loads).
* Be sure that your Javascript files (.js) do not include the <script> tag. They should only have the HTML comment and Javascript code.
Javascript Operators - các toán tử sử dụng
Javascript Operators - các toán tử sử dụng
Operators in Javascript are very similar to operators that appear in other programming languages. The definition of an operator is a symbol that is used to perform an operation. Most often these operations are arithmetic (addition, subtraction, etc), but not always.
You will want to bookmark this page for future reference.
Javascript Arithmetic Operator Chart
| Quote: : |
Operator English Example
+ Addition 2 + 4
- Subtraction 6 - 2
* Multiplication 5 * 3
/ Division 15 / 3
% Modulus 43 % 10 |
Javascript Operator Example with Variables
Performing operations on variables that contain values is very common and easy to do. Below is a simple script that performs all the basic arithmetic operations.
HTML & JavaScript Code:
| Code: : |
<body>
<script type="text/javascript">
<!--
var two = 2
var ten = 10
var linebreak = "<br />"
document.write("two plus ten = ")
result = two + ten
document.write(result)
document.write(linebreak)
document.write("ten * ten = ")
result = ten * ten
document.write(result)
document.write(linebreak)
document.write("ten / two = ")
result = ten / two
document.write(result)
//-->
</script>
</body> |
Display:
| Quote: : |
| two plus ten = 12ten * ten = 100ten / two = 5 |
Comparison Operators
Comparisons are used to check the relationship between variables and/or values. A single equal sign sets a value while a double equal sign (==) compares two values. Comparison operators are used inside conditional statements and evaluate to either true or false.
| Quote: : |
Operator English Example Result
== Equal To x == y false
!= Not Equal To x != y true
< Less Than x < y true
> Greater Than x > y false
<= Less Than or Equal To x <= y true
>= Greater Than or Equal To x >= y false |