otnj2ee
09-11-2008, 12:02 AM
A parent.jsp page is constructed as:
<head>
<script language="JavaScript" type="text/javascript" src="js/test.js?</script>
</head>
<body>
<div id="placeHolder">
</div>
</body>
Later on at the run time, the div section will be dynamically loaded by the returned child.jsp (from the server side), which contains:
<input type="button" value="test" onclick="test()" />
--Now, if I put the test() function inside the test.js, such as
<script type="text/javascript" language="javascript">function test(){ alert("testing");} </script>
onclick will trigger the function.
--But, if I put the same function in the child.jsp page, instead. onclick can NEVER trigger the function.
Why?
Scott
Dynamical loading used: document.getElementById("...").innerHTML="..."
Yes, I also changed and resaved the parent.jsp.
<head>
<script language="JavaScript" type="text/javascript" src="js/test.js?</script>
</head>
<body>
<div id="placeHolder">
</div>
</body>
Later on at the run time, the div section will be dynamically loaded by the returned child.jsp (from the server side), which contains:
<input type="button" value="test" onclick="test()" />
--Now, if I put the test() function inside the test.js, such as
<script type="text/javascript" language="javascript">function test(){ alert("testing");} </script>
onclick will trigger the function.
--But, if I put the same function in the child.jsp page, instead. onclick can NEVER trigger the function.
Why?
Scott
Dynamical loading used: document.getElementById("...").innerHTML="..."
Yes, I also changed and resaved the parent.jsp.