js.html文件<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript" src="01.js" ></script>
</HEAD> <BODY>
<form action="" method="post">
<p>
<input name="name" id="name" type="text" />
<input name="" value="测试" type="button" onClick="aa()">
<script type="text/javascript" src="02.js"></script>
</p>
</form>
</BODY>
</HTML>
01.jsfunction aa(){
document.write('<scri'+'pt type="text/javascri'+'pt" src="02.js"></scri'+'pt>');
alert('测试成功');
}
02.js
document.getElementById('name').value = '张三' ;
在点击测试按钮时,页面内容就不显示了,好像提交了表单,怎么才能在点击了测试按钮后,输入框显示“张三”,然后弹出 测试成功 ?各位有没有好的解决办法,谢谢!
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript" src="01.js" ></script>
</HEAD> <BODY>
<form action="" method="post">
<p>
<input name="name" id="name" type="text" />
<input name="" value="测试" type="button" onClick="aa()">
<script type="text/javascript" src="02.js"></script>
</p>
</form>
</BODY>
</HTML>
01.jsfunction aa(){
document.write('<scri'+'pt type="text/javascri'+'pt" src="02.js"></scri'+'pt>');
alert('测试成功');
}
02.js
document.getElementById('name').value = '张三' ;
在点击测试按钮时,页面内容就不显示了,好像提交了表单,怎么才能在点击了测试按钮后,输入框显示“张三”,然后弹出 测试成功 ?各位有没有好的解决办法,谢谢!
<BODY onload="js()">
function js(){document.getElementById('name').value = '张三' ;
}
script.type = "text/javascript"
script.src = "02.js";var related = document.getElementsByTagName('script')[0];
related.parentNode.insertBefore(script, related);
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</HEAD> <BODY>
<form action="" method="post">
<p>
<input name="name" id="name" type="text" />
<input name="" value="测试" type="button" onClick="aa()">
</p>
</form>
</BODY>
<script type="text/javascript" src="01.js"></script> <!-- 一定放body 之后 -->
</HTML> 01.js:
// 动态导入js
function include(src,encoding,fun)
{
var s = document.createElement('script');
s.type='text/javascript';
s.charset=encoding; //'gb2312';
s.src = src;
var tags =$$('head');
if(typeof(fun)=='function'){
if( document.all ){
s.onreadystatechange = function(){
if(/(complete|loaded)/.test(this.readyState)){
fun(); s.onreadystatechange = null; s.parentNode.removeChild(s);
}};
}else{
s.onload = function(){ fun(); s.onload = null; s.parentNode.removeChild(s); };
}
}
tags[0].appendChild(s);
};function aa(){
include("02.js","gb2312",function(){alert('测试成功');});
}
02.js
document.getElementById('name').value = '张三' ;