Javaweb Learning Content

Source: Internet
Author: User
Tags file url logical operators

One:
1. Two functions commonly used in JavaScript
Alert ("Popup a Hint box");
document.write ("Output content to browser")

alert("今天德国大胜吗?") ;向浏览器输出内容document.write("今天天气不错!!") ;2.关于JavaScript的变量的定义        var 变量名= 值;        注意:            1)在js中,var可以用来定义任何数据类型的变量,var 可以省略,但是不建议省略            2)var是可以重复定义变量的(后面的值会覆盖掉前面的值),是因为JavaScript弱类型语言,而Java是一种强类型语言            3)如果定义一个变量,但是变量没有值,那么值(undefind),没有定义的变量不能直接使用!            查看一个变量的数据类型,使用一个函数:typeOf(变量名)            Javascript数据类型:                    在javascript,数据类型变量名的值来决定的!                  1)不管是整数还是小数都是number类型!                2)不管是字符还是字符串,都是string类型         String:在js中表示字符串对象                3)boolean类型                4)object   :对象类型

3.!--
Type conversion function

        String----Number type integer parseint (variable) stirng----number type decimal parsefloat (variable)--><script Type= "Text/javascript" >//define a variable var a = "10";    String: The value inside the document.write ("The data type of the before conversion is:" +typeof (a) + "<br/>");    Convert a = parseint (a);    document.write ("The data type of the converted A is:" +typeof (a) + ", the value is:" +a);    document.write ("

document.write ("<table align= ' center ' >");
for (var i = 1; i <=9; i++) {
//
for (var j = 1; j<=i; j + +) {
document.write (i+ "" +j+ "=" + (ij) + "");
}
document.write ("<br/>");
}

document.write ("</table>");
*/

 //with语句 with(document){ for(var i = 0 ; i < 5 ; i ++){ for(var j = 0 ; j <=i ; j++){ write("*&nbsp;"); } write("<br/>") ; } write("

7. Definition of function:

    • 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 () + "&nbsp;&nbsp;"    + 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" + "&nbsp;&nbsp;");    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]+"&nbsp;") ;    }*/    /**     * 两个方法     *  join():将数组中的所有元素以一个符号进行拼接,返回一个新的字符串     * reverse 方法:将数组中的元素进行反转
  1. The custom object definition object in
  2.   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);

  3. 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

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.