解决方案 »
- 为什么这样行不通呢?本人才学,见谅。。。
- 如何实现随机加载不同的js
- 试试这个页面,如果去掉滚动条?
- js如何在子页面里调用checkboxlist下的值返回到父页面中??(新手问题)
- [DOM] nodeName = "#text",可是我要取它的节点名字 怎么办?
- 请教高手 :用VB语句如何 向谷歌地图js传递参数 ?
- 关于数组形式的表单计算,请高手帮我转成多行可计算的表单!
- 在html页面中使用客户端如何打开一个新页面?如何打开一个焦点无法转移的新页面(即不关闭新页面就无法回到打开它的那个页面)?
- 请教checkbox一个问题!在线等!谢谢
- highcharts 后台连数据库
- jquery 选择元素的问题
- 使用document向html输出一组checkbox
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function myFunction()
{
alert("Hello World!");
}
</script>
</head>
<body>
<script type="text/javascript">
document.write('<button onclick="return myFunciton();"> Click Me');
document.write('</button>');
</script>
<p>By clicking the button above, a function will be called. The function will alert a message.</p>
</body>
</html>
这个运行的话点击没有用,也是现实函数未定义。求教啊,是不是不能用document.write来写啊?
<html>
<head>
<script type="text/javascript">
function myFunction()
{
alert("Hello World!");
}
</script>
</head>
<body>
<script type="text/javascript">
document.write('<button onclick="myFunction()"> Click Me');
document.write('</button>');
</script>
<p>By clicking the button above, a function will be called. The function will alert a message.</p>
</body>
</html>
这样就可以弹出来了
我重新写了一个例子,我觉得是因为window.onload函数的原因,但是不知道怎么解决,代码如下:<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
//在这里单独添加也不行
function myFunction(i)
{
alert("Hello World!");
}
</script>
</head>
<body>
<script type="text/javascript">
window.onload = function()
{
//我在这里单独添加过,也不行
function myFunction(i)
{
alert("Hello World!");
}
var tcount=1;
document.write('<a href ="#" onclick="myFunction(tcount)"> Click Me');
document.write('</a>');
}
</script>
<p>By clicking the button above, a function will be called. The function will alert a message.</p>
</body>
</html>
谢谢了!
document.write('<a href ="#" onclick="myFunction(tcount)"> Click Me');
document.write('</a>');
这2句代码你明白什么意思吗?
不明白你可以右键查看页面源代码你会发现页面上就剩这一句了
<a href ="#" onclick="myFunction(tcount)"> Click Me</a>
//在这里单独添加也不行
function myFunction() { alert("Hello World!");
}
还有你的这个函数不行上面我也说了你一个document.write把整个页面重写了,要想函数能执行也得把函数写进去,把你的给你改了下你试试
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
//在这里单独添加也不行
function myFunction() { alert("Hello World!");
}
</script>
</head>
<body>
<script type="text/javascript">
window.onload = function () {
var tcount = 10000;
document.write("<script type=\"text/javascript\">function myFunction(i){ alert(i);}<\/script>");
document.write('<a href ="#" onclick="myFunction('+tcount+')"> Click Me');
document.write('</a>');
}
</script></body>
</html>