JavaScript mates Button.onclick () Usage Summary

Source: Internet
Author: User

The HTML loading order is loaded from top to bottom, if the script contains a reference JS script, you should put this script in the head tag, so that the page can be used to refer to the JS script content. If you want to set the Button.onclick () event in script, this script should be placed after the button declaration.

Example: index.jsp

<%@ Page Language="Java"Import="java.util.*"pageencoding="UTF-8"ContentType="text/html; Charset=utf-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"><HTML><Head><title>JavaScript and Button.onclick () events</title><Metahttp-equiv= "Pragma"content= "No-cache"><Metahttp-equiv= "Cache-control"content= "No-cache"><Metahttp-equiv= "Expires"content= "0"><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><!--full-Text related script scripts (including referenced script files) are placed in the head tag -<Scripttype= "Text/javascript"src= "Include.js">    functionfun1 () {alert ("The first script mode shows the time:" +Date ()); }</Script></Head><Body>    <ButtonID= "Button11"onclick= "fun1 ()">The first script mode shows the time</Button>    <ButtonID= "Button12"onclick= "fun2 ()">Show time by referencing JS file</Button>    <ButtonID= "Button2">The second script mode shows the time</Button>    <ButtonID= "Button3">The third script mode shows the time</Button>    <Script>document.getElementById ("Button2"). onclick= function() {displaydate ()}; document.getElementById ("Button3"). onclick=DisplayDate2; functiondisplaydate () {document.getElementById ("Demo"). InnerHTML= "The second script mode shows the time:"                    +Date (); }        functionDisplayDate2 () {document.getElementById ("Demo2"). InnerHTML= "The third script mode shows the time:"                    +Date (); }    </Script>    <BR>Time One:<PID= "Demo"></P>Time Two:<PID= "Demo2"></P></Body></HTML>

Include.js

    function fun2 () {        alert ("Show time by reference JS file:" + date ());    }

Enter the URL: http://localhost:8080/Test/index.jsp, as follows

JavaScript mates Button.onclick () Usage Summary

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.