Академический Документы
Профессиональный Документы
Культура Документы
External:
<script> tag
Indicate that the text is part of a script
type attribute
<html>
<head>
<script src="xxx.js"></script> 1
<script type="text/javascript”> 2
</script>
</head>
<body>
<script type="text/javascript”> 3
</script>
<script src="xxx.js"></script> 4
</body>
</html>
Window.alert(“message”)
Window.write(“text”)
Window.prompt(“sometext”, “default text”)
Window.confirm(“text”)
Subtraction - p–c p - c
Multiplication * bm b * m
Division / x / y or or xy x / y
Remainder % r mod s r % s
Fig. 7.12 Arithmetic operators.
Do NOT confuse relational equality operator “==“ with an assignment operator “=“
Order of Precedence for the
Basic Operators
highest
Operators Associativity Type
* / % left to right multiplicative
+ - left to right additive
< <= > >= left to right relational
== != left to right equality
lowest = right to left assignment
Fig. 7.17 Precedence and associativity of the
operators discussed so far.
The JavaScript var (for variable) can be
<html> used to define a field (note that you can
<script language="JavaScript"> eliminate the command var and it will still
var ans = 0; work). In this example, I have defined
var firstnum = 0; three variables and given them all an
initial value of 0.
var secondnum = 0;
firstnum = prompt("Enter the first number",0);
secondnum = prompt("Enter the second number",0);
ans = firstnum * secondnum;
document.write(ans); The prompt can be used to take in
</script> data. The message in quotes is
</html> used to ask the user for input and
the 0 indicates it is numeric input.
Note that the data that was keyed in
ans = firstnum * with the first prompt was assigned
to firstnumand the data that was
secondnum; keyed in with the second prompt
This takes the two numbers was assigned to secondnum.
stored in firstnum and document.write(ans);
secondnum and multiplies
them together. The results are I am now using the write method
stored in ans. to put ans to the screen. Note
that ans is a variable, not a literal
so it is not enclosed in quotes.
<html>
<script language="JavaScript">
var ans = 0;
var firstnum = 0;
var secondnum = 0;
firstnum = prompt("Enter the first number",0);
secondnum = prompt("Enter the second number",0);
ans = firstnum * secondnum;
document.write("The answer is ", ans);
</script>
</html>
Go to
https://www.w3schools.com/js/default.asp
To learn more about the language
jQuery
Basic Syntax:
$(Selector).action( );
o $ to access jQuery
o Selector to find the HTML element
o action to be performed on the selector
The selector might be:
Tag $(“h1”).action( );
Class $(“.className”).action( );
Id $(“#idName”).action( );
First jQuery
$("#a1").click(function(){
$("#home").hide();
$("#faq").hide();
$("#list").hide();
$("#signup").show();
});
//slideToggle
$("#parent-list").click(function(){
$("#list").slideToggle();
});
//fadeToggle
$("img").click(function(){
$("img").fadeToggle("slow");
});
Append
Prepend
Before
After
jQuery Add
Single modification:
$(selector).css(“propertyname”, “value”);
Multiple Modifications:
$(selector).css({“propertyname”: “value”,
“propertyname”: “value”, …);
Example:
$("#s1").css({"background-color": "yellow",
"color": "green"});
jQuery Form Validation
$(form).validate({
rules: { fieldName: ..
},
messages:{ filedName:
}
});