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>