Copy codeThe Code is as follows:
<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>
<%
String path = request. getContextPath ();
String basePath = request. getScheme () + "://"
+ Request. getServerName () + ":" + request. getServerPort ()
+ Path + "/";
%>
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
<Html>
<Head>
<Base href = "<% = basePath %>">
<Title> My JSP 'createelement. jsp 'starting page </title>
<Meta http-equiv = "pragma" content = "no-cache">
<Meta http-equiv = "cache-control" content = "no-cache">
<Meta http-equiv = "expires" content = "0">
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "description" content = "This is my page">
<Script type = "text/javascript"
Src = "<% = request. getContextPath () %>/jquery/jquery-1.7.min.js"> </script>
<Script type = "text/javascript">
$ (Function (){
$ ("# But"). click (function (){
Var para = document. createElement ("p ");
Var node = document. createTextNode ("this is a new section. ");
Para. appendChild (node );
Var element = document. getElementById ("div1 ");
Element. appendChild (para );
})
})
</Script>
</Head>
<Body>
<Div id = "div1">
<P id = "p1">
This is a paragraph.
</P>
<P id = "p2">
This is another paragraph.
</P>
</Div>
<Input type = "button" id = "but" value = "add">
</Body>
</Html>