如何才能用href调用嵌套函数?

GoAndSeek 2007-12-25 09:50:29
<html>
<script type='text/javascript'>
function create_link()
{
function _alert() {
alert("hello");
}
var div=document.createElement('div');
div.innerHTML = "<a href=\"javascript:_alert()\">alink</a>"
document.getElementById('h').appendChild(div);
}
</script>
<body>
<h4 id='h'></h4>
<input type='button' value='create' onmouseup='create_link();' />
</body>
</html>

现在需要用href调用嵌套函数,代码和上面类似发现不行。大伙有什么解决方法?谢谢
...全文
137 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhengshaodong 2007-12-25
  • 打赏
  • 举报
回复

<html>
<script type='text/javascript'>
function Hello() {
alert("hello");
}
function create_link()
{

var div=document.createElement('div');
div.innerHTML = " <a href=\"javascript:Hello()\"> alink </a> "
document.getElementById('h').appendChild(div);
}
</script>
<body>
<h4 id='h'> </h4>
<input type='button' value='create' onmouseup='create_link();' />
</body>
</html>

dh20156 2007-12-25
  • 打赏
  • 举报
回复
你的
function _alert() {
alert("hello");
}
是 function create_link() 的私有函数,怎么可以访问得到!
GoAndSeek 2007-12-25
  • 打赏
  • 举报
回复
有什么办法可以访问嵌套函数?

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧