JS动态为UL创建1个LI 为LI绑定一个Onlick事件。怎么做?
解决方案 »
- jquery 图片滑动
- 求助网站访问信息
- 不知道在线编辑器的 [自动排版]功能怎么做!我看fck也没有这个功能!只有
- 请问这2段js文件是什么意思啊,怎么出现yahoo字样
- ★如何获取JS代码的源内容?
- TABLE的撤消行的问题。。
- 局域网内使用地图
- 求助一个问题我用jquery动态添加html元素,比如:var html = '<input type="text"'+ 'placeholder=' + st
- JS设置cookie连续超过20个值后冲掉domino服务器设置的DomAuthSessId,导致用户需要重登陆问题
- js公告文字滚动效果(只滚动一点点的距离就从头开始滚动了,应该滚动到屏幕最后面才对啊)
- 继续Doodle收集:粘土动画大师阿特·克洛基纪念Doodle
- flex4.1下载包文件问题
<!doctype html>
<html>
<head>
<meta charset="gb2312" />
<title></title>
<style>
</style>
</head>
<body>
<ul id="test">
</ul>
<script>
function $(o){return document.getElementById(o)}
var li = document.createElement('li');
li.innerHTML = 123;
li.onclick = function(){
alert(123)
}
$('test').insertBefore(li, $('test').firstChild)
</script>
</body>
</html>
用appendChild
up~`用 $('test').appendChild(li)
$("li.xxx").each(function() {
if (!$.data(this, 'events') || $.data(this, 'events').mousedown === undefined) {
$(this).mousedown(function() {
//do something
});
}
});
$("ul>li").bind({
click:function(){
if($(this).hasClass("red")){
$(this).removeClass("red").addClass("blue");
}else{
$(this).removeClass("blue").addClass("red");
}
}
});
});动态给li绑定click事件,点击li进行class的red,blue变换,参考下吧