javascript动态创建脚本的问题

来源:百度知道 编辑:UC知道 时间:2024/06/29 02:14:34
有这样一个问题。。。如下代码
<html>
<head>
</head>

<script type="text/javascript">
function add(){
}
</script>
<body>
<input type="button" onClick="show()" value="测试">
<input type="button" onClick="add()" value="增加">
</body>
<html>
直接点测试按钮会出错。我想点增加后,动态创建一个show()方法。我是这样想的。。。用document.createElement()新创建一个script。然后往里面增加方法。。但是提示类型不匹配。。。请问怎么解决呢。。:-)
<html>
<script type="text/javascript">
function add(){
var s="<SCRIPT type=text/javascript>function show(){alert(\"Hello\");}<\/script>";

}
</script>
<body>
<input type="button" onClick="show()" value="测试">
<input type="button" onClick="add()"

你没有写出show方法
<html>
<head>
</head>

<script type="text/javascript">
function add(){
}
function show(){
}
</script>
<body>
<input type="button" onClick="show()" value="测试">
<input type="button" onClick="add()" value="增加">
</body>
<html>
这样至少不报错了
-----------------------------
好的我再给你调试调试
---------------------------------------
对不起了兄弟,我调试了半天也没搞对
我用的是document.write();

<html>
<head>
</head>

<script type="text/javascript">
function add(){

function show(){
alert("11223");
}
document.getElementById("show").onclick = show;
}
</script>
<body>
<input type="button" id="sh