假如想利用js动态增加的控件,请问该如何添加onclick方法?

<script type="text/javascript">

function add(e){

var container = document.getElementById('content');
var text = document.getElementById(e).innerHTML;
var newNode = document.createElement("span");
newNode.innerHTML = text;
container.appendChild(newNode);

var ui =document.getElementById(e);
ui.style.visibility="hidden";

}

</script>

</head>

<body>

<div style="border:1px #66FFFF solid;font-family:'微软雅黑'">
<h3 style="font-family:'微软雅黑'">我的爱好</h3>
<div>
<p >先从你喜欢的东西开始,让别人了解你。</p>
<div >
<p>通过单击以下标签进行选择:<a href="#" title="换一组标签" >换一下</a></p>
<div id="option">
<span id="0_杨澜" onclick="add(this.id)">杨澜</span>
<span id="0_马艳丽" onclick="add(this.id)">马艳丽</span>

</div>
</div>

<div id="content" style="width:400px;height:200px;border:2px #99CCFF solid ">

</div>

</div>
</body>
点击标签后,下面的div中增加,如何删除增加的标签呢?写不了onclick方法,求大神帮忙修改下

qq_花开花谢_0
浏览 333回答 2
2回答

HUWWW

绑定事件的兼容写法:function addEvent(obj,e,fun){obj.attachEvent ? obj.attachEvent("on"+e,fun) : obj.addEventListener(e,fun,false);}//为xxx绑定click事件addEvent(xxx, "click", function(){//....});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

CSS3
Html5