解决方案 »
- 怎样删除指定div后的所有内容
- 仿新浪微博返回顶部怎样用纯JS做?
- 为什么大多数网页都用js脚本而不用vbs呢?
- 点击文本框后面的时间图片,弹出一个窗口,选中年月日和具体时间后,可以自动将其时间显示在文本框中。
- 求教一个Target = "_Blank"在Netscape(Mozilla)无法工作问题
- html中调用javascript函数中怎样传递数组
- 送分啦,一个按钮背景变换问题!欢迎大家探讨!^Q^
- 怎样在关闭窗口1的时候,刷新窗口2?急急急!!!
- 請問javascript的參數類型如果是字符串的話﹐最大的長度是多少個英文字符﹖
- 求助,关于html2canvas.js,将DIV内容写入Canvas生成图片
- 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>