fuction hello(){
alert('hello world');
}span=document.createElement("span");
span.id="FT";
span.onclick='hello()';我想要点击时调用hello()方法;
span.innerHTML='hello';
span.style.background="yellow";
document.getElementById('T0').appendChild(span);HTML部分是
<div id="T0"></div>就是达到这个效果:
<div id="T0"><span onclick="hello()">hello</span>
解决方案 »
- input 文本框 有文本时触发的事件
- js里var $bud = "undefined";这个表求什么意思?
- JS 文件内部可否包含另一个js
- 如何寻找页面javascript函数的代码
- js时间控件谁有啊
- 谁有JavaScript讲座的PPT文档,方便给我一份,谢谢! (100求助)
- 如何替換標簽里面的<br>
- javascript中有什么函数可以取得浏览器滚动条的位置?(很菜的问题)
- 帮小弟看看这段程序!!!
- 地图截图功能
- 页面有一个div标签、两个按钮,要求用按钮控制这个div的颜色,一个button将div背景设置为红色,另一个button将div背景设置为绿色。写了代码,就是没有效果帮看看
- 请问替换中文字符问题
<html>
<body>
HTML部分是
<div id="T0"></div>
<script>
function hello(){
alert('hello world');
}
span=document.createElement("span");
span.id="FT";
span.onclick = hello; //我想要点击时调用hello()方法;
span.innerHTML='hello';
span.style.background="yellow";
document.getElementById('T0').appendChild(span);
</script>
</body></html>