- Function name (formal parameter list)//{
- Statement
- }
- Call to function
- Function name (actual argument list);
- Considerations in the function:
- 1) function of the formal parameters can not have the var keyword definition, or error
- 2) in JS, the function can have a return statement, direct return, but no return value
- 3) in JS, the function is a non-existent overload concept, the function defined in the back overrides the previously defined function
- 4) When the number of actual parameters is less than the number of formal parameters, a value is definitely nan, and if the actual parameter is greater than the formal parameter, then the previous value will be computed, and then the data behind will be discarded!
5) in each of the JS functions, there is a default array: arguments, its function is to assign the actual parameters from left to right in order to the formal parameters (from left to right)
8.
Mode 1
String str = new string ();
var str1 = new String ("Hello");
/*var str2 = new String ("Hello");
document.write ((STR1==STR2) + "<br/>");
In JS valueOf () The default comparison is whether their content is the same document.write (Str1.valueof () ==str2.valueof () + "<br/>"), *///creation Method 2//Direct assignment of the form/ *var S1 = "Hello"; var s2 = "Hello";d ocument.write (s1==s2+ "<br/>");d Ocument.write (s1.valueof () ==s2.valueof ()); * Common methods of String objects in JS//chatat (): Returns the character at the specified index position//indexof (): The index//lastindexof () that represents the first occurrence of a substring in the current string;//fontcolor (): Sets a color marker for the current string//substrint (start,end): Intercept function 9. Rounding up//in integer position +1 var num = 4.30; document.write (Math.ceil (num) + "<br/>"); Rounding down: If there are fractional parts, the decimal part is removed, and the integer digits document.write (Math.floor (num) + "<br/>") are retained; Rounded document.write (Math.Round (num) + "<br/>"); Random number (): contains 0, but does not contain 1 document.write (Math.random () *100+ "<br/>"); Max/min document.write (Math.max (num,100)); 10.function newdate () {//Generate a System time format: 2018-6-17: minutes: seconds//Create Date object var date = new Date (); DATESTR is the system time var datestr = date.getfullyear () + "-" + (Date.getmonth () +1) + "-" +date.GetDate () + " " + date.gethours () + ":" +date.getminutes () + ":" +date.getseconds (); Gets the span tag object, obtained by id var datetip = document.getElementById ("Datetip"); Datetip is null//Set InnerHTML property for span Label: Text Property datetip.innerhtml = Datestr;} Timer//1) setinterval ("task", millisecond value); This task (function)//2) timeout ("task", millisecond value) is repeated every number of milliseconds, after which the task Window.setinterval ("Newdate ()", 1000) is executed once after a few milliseconds; 11.//how to create a Date object var date = new Date (); alert (date); Sun June 2018 16:05:35 gmt+0800 (China Standard Time)//Acquisition system time: June 17, 2018 XXX: xx minutes: xx seconds--->java there is a class: Simpledatefo Rmat//getfullyear: Get the Year document.write (Date.getfullyear () + "year"); Get Month: GetMonth method returns an integer from 0 to 11, document.write ((Date.getmonth () +1) + "month"); Gets the date in the month document.write (date.getdate () + "Day" + " "); Get the hours of the day document.write (date.gethours () + ":"); Get Sub Document.Write (Date.getseconds () + ":"); Gets the seconds of the Minute document.write (Date.getminutes ()); _____________________________________________________ One: 1. How array objects are created * * NOTE: * 1) in JS, the array can store any type of element! * 2) in JS, there is no array angle index out of bounds one said that the number of elements in the array can be continuously increased. There will be no exceptions! * *///Mode 1: Equivalent to dynamic initialization of//1.1
var arr = new Array (3);
var arr = new Array (); Represents 0 Lengths
/*alert(arr.length) ; //给元素赋值 arr[0] = "hello" ; arr[1] = 100; arr[2] = true ; arr[3] = "world" ; alert(arr.length) ;*/ //1.3 直接指定数组中 具体元素
var arr = new Array ("Hello", 100,true, ' a ');
//方式2 :直接指定数组的元素,不需要new Array() ;类似于Java中数组的静态初始化; /*var arr = [10,"hello","world",true] ; //遍历数组 for(var i = 0 ; i < arr.length ;i++){ document.write(arr[i]+" ") ; }*/ /** * 两个方法 * join():将数组中的所有元素以一个符号进行拼接,返回一个新的字符串 * reverse 方法:将数组中的元素进行反转
- The custom object definition object in
-
JS 1) is equivalent to the form of a parametric construct 2) A form function custom object (person) (parameter name) without a parameter construct { Define attribute//Definition method} Create object var p = new Preson (actual parameter); The value of the property in the Output object P//Call Method 3 in the object p. Design an array tool object, such as the Arrayutil object, which provides the following two methods: Search (Array,target): Passes in the specified array and the specified string, returns the location of the specified string, max (array): Passing in the specified array, Returns the maximum value in the array-->//creates an array, statically initializes the
var arr = [43,65,13,87,3,19];
//Create Arrayutil object
var arrayutil = new Arrayutil ();
//Query 3 This element corresponds to the index
var index = arrayutil.search (arr,300);
document.write ("The location of the element you are looking for is:" +index);
document.write ("
//Get maximum value in arr
var max = Arrayutil.max (arr);
document.write ("The maximum value in the current array is:" +max);
Problem: Just used to customize an object Arrayutil object, complete just query and the most value operation;
How to append Search () and Max () to an array (JS built-in object) object without providing any tool classes
There are methods for array objects
function Array () {
this.join = function() { } this.reverse = function(){ } //追加 this.search() = function(){ } //这样写就不行了,因为Array对象是内置对象,不能直接这做,获取不到源码!}
Prototypes (prototype)
Function: is to give JS in the built-in object Append method to use the
1) Each JS built-in object has a prototype attribute (prototype)
2) If you append a method to the prototype object, the method is automatically appended to the built-in object
3) The prototype attribute can be called directly by the built-in object and then appended to the method
//原理/定义了原型对象function Prototype(){ this.search = function(){ }}function Array(){ //创建原型对象 var prototype = new Prototype() ; //自动追加 this.search = function(){ }}-->
<script type= "Text/javascript" >
Prototyping improvements using built-in objects
Append search to the array object
Array.prototype.search = function (target) {
Iterating through an array in an array object
for (var i = 0; i< this.length; i++) {
Judge
if (this[i] = = target) {
return i;
}
}
Not found, return-1
return-1;
}
The prototype property of the built-in object is appended with Max () Array.prototype.max = function () {//define reference var max = this[0]; Traverse other elements for (var i = 1; i < this.length; i++) {//To determine if (This[i] > max) {max = this[i]; }} return max;} Create an array, statically initialize var arr = [43,65,13,87,3,19]; var arr = new Array (43,65,13//), var index = Arr.search (3);d ocument.write ("The position of the element you are looking for is:" +index+ "<br/>"); var max = Arr.max ();d ocument.write ("The maximum value in the array is:" +max); 5. Window object: It represents a Windows object of the browser note: Because the methods in the Window object are frequently called, window can sometimes remove the method involved in order to simplify the writing process: Open ("Opening resource file URL", "What is the way to open (_blank)/_self", "Specify newly opened window and height") and timer-related methods: SetInterval ("task", Time ms Value); Repeat this task after a few milliseconds clearinterval (): Canceling and setinterval related Tasks Window.clearinterval (iintervalid): This is going to insert a Id setTimeout ("task", time millisecond value); The number of milliseconds after which only one cleartimeout (): Cancels and settimeout related timeout events and the Bullet Box related method Window.alert ("Prompt box"); Window canOmit window.confirm (message dialog box); There is a confirmation box, prompt: Prompt dialog box with a message and an input box--
<script type= "Text/javascript" >
Triggering an open Click event
function testOpen(){ //调用open 方法 window.open("06.广告页面.html","_blank") ; } //和定时器相关的函数 //定义一个任务id var taskId ; function testSetInterval(){ //每经过2秒重复执行testOpen taskId = window.setInterval("testOpen()",2000) ; } //清除和setInterval相关的定时器 function testClearInterval(){ //调用功能 window.clearInterval(taskId) ; } //定位任务id var timeoutId ; //setTimeOut定时器 function testSetTimeout(){ //经过3秒后执行testOpen函数 timeoutId = window.setTimeout("testOpen()",3000) ; } function testClearTimeout(){ window.clearTimeout(timeoutId) } //alert的方法 function testAlert(){
Window.alert ("Nice Day today ....");
Alert ("Nice Day today ....");
}
function testConfirm(){ //调用 var flag = window.confirm("确认删除吗?一旦删除,数据不可恢复!!") ; if(flag){ alert("数据已删除") }else{ alert("您取消了删除") ; } } //和确认提示框,有一条消息 function testPrompt(){ var flag = window.prompt("请您输入u顿密码!") ; if(flag){ alert("输入正确"); }else{ alert("请重新输入"); } }6. location对象: href属性:可以修改页面的href属性来实现页面跳转 更改的href属性:--- URL(统一资源定位符) URI 方法: 定时刷新:reload() -->
<script type= "Text/javascript" >
//loaction:地址栏对象 function testHref(){
alert (WINDOW.LOCATION.HREF);
//修改location的href属性 window.location.href="06.广告页面.html" ; //location的 href属性 } function testRelod(){ //调用reload定时刷新 window.location.reload() ; } //定时刷新:reload()
function Testrefresh () {
//定时器 window.setTimeout("testRelod()" ,1000) ;
// }
7. history对象中的方法 forward:装入历史列表中下一个url back:装入历史列表中前一个url go(正整数或者负整数)
-
<script type= "Text/javascript" >
function testForward(){ //调用功能
Window.history.forward ();
window.history.go(1) ;}8.事件编程的分类: 1)和点击相关的事件 单击点击事件: onclick 双击点击事件: obdbclick 2)和焦点相关的事件 获取焦点事件:onfocus 失去焦点事件:onblur 3)和选项卡发生变化
-->
<script type= "Text/javascript";
and click Click Related Function Testclick () {alert ("point ..."); }//Double-click function Testdbclick () {alert ("You have to double-click ..."); }//Get focus (in JS, generally if you want to get a tag object, the best way to use it is to give it a id,id is unique) function Testfocus () {//id attribute var usrename = doc Ument.getelementbyid ("username"); Gets the Label object username.value = ""; }//Lose focus (the mouse cursor is removed from the text input box) function Testblur () {//Gets the user's content in the text input box var username = document.getElementById ( "username"). Value; Gets the span tag object var nametip = document.getElementById ("Nametip"); If the value entered is not "Eric", the user name does not match the rule if (username = = "Eric") {//Nametip set innerHTML property nametip.innerhtm L = "Verify success, conform to rules". FontColor ("#00ff00"); }else {nametip.innerhtml = "user name does not match the rules". FontColor ("#ff0000"); }} 9. <!--events related to tab changes: OnChange (Dropdown menu, select tab) and mouse related events: onmouseover: Mouse over event onmouseout: Mouse out Event and page load related events: OnLoad is generally used in the body This event 10 is triggered when the contents of the body are loaded.
Javaweb Learning content