Notes for introducing JS files in JSP page scripts

Source: Internet
Author: User

Sometimes, we have a lot of repeated code in the script code on multiple JSP pages, so we will think about how to reuse them. When using it, we need to pay attention to several issues:
For example, there are two files: toolbar. js and Main. jsp.

Toolbar. JS:
========================================================== ========================================================== ======
Ext. blank_image_url = '/ngrcms/images/s.gif ';
VaR clientwidth = Document. Body. clientwidth;
VaR clientheight = Document. Body. clientheight;
 
VaR button = new Ext. Button ({
Text: 'click ',
Icon: '../images/query.png ',
CLS: "X-BTN-text-icon ",
Scope: This
});
========================================================== ========================================================== ======

Main. jsp:
========================================================== ========================================================== ======
<% @ Page Language = "Java" pageencoding = "UTF-8" %>
<HTML>
<Head>
<Title> reporttest </title>
<LINK rel = "stylesheet" type = "text/CSS" href = "../ext-3.2.1/resources/CSS/ext-all.css">
<SCRIPT type = "text/JavaScript" src = "../ext-3.2.1/adapter/EXT/ext-base.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "../ext-3.2.1/ext-all.js"> </SCRIPT>
</Head>
<Body>
<Div id = "Container">
</Div>
// Note that the toolbar. js contains the document. Body. clientwidth operation on the body. Therefore, when importing a JS file, you must put it in the body,
// Cannot be placed in the head. Because no body is generated during head execution, the attributes undefined will be generated.
<SCRIPT type = "text/JavaScript" src = "toolbar. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
Button. On ('click', function (){
Ext. MessageBox. Alert ("this is a query button ");
});

Ext. onready (function (){
VaR Panel = new Ext. Panel ({
Layout: 'fit ',
Frame: True,
Title: 'title ',
Width: clientwidth,
Height: clientheight,
Renderto: 'Container'
});
});
</SCRIPT>
</Body>
</Html>

Related Article

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.