Jquery小问题

passself 2009-12-23 08:45:52
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js树型测试</title>
<style>
#tree{
width:200px;
height:400px;
border:1px solid red;
margin-left:400px;
margin-top:100px;
}
#root{
margin-left:10px;
float:left;
}
#change_pic{
float:left;
height:16px;
border:1px green solid;
}
#computer{
float:left;
height:16px;
width:180px;
border:1px solid red;
}
.listStyle{
min-width:100px;
width:auto;
height:16px;
margin-left:10px;
margin-top:3px;
font-size:15px;
font-family:"幼圆";
font-weight:normal;
cursor:pointer;
color:#000000;
border:1px solid green;
}
.pic{
width:12px;
height:12px;
}
.pic_name{
float:left;
}
</style>
<script src="js/jquery-1.3.2.js"></script>
<script>
$(document).ready(function(){
//初始化
$("#root").append("<div id='computer' class='style1'><img src='images/computer.png' width='12px' align='bottom' /> 设备列表</div>");
$(".style1").prepend("<img src='images/blue_velvet_003.png' class='imgStyle1' align='bottom' style=' width:12px;height:12px;'/>  ");


$(".style1").click(function(){
$("#root").append("<div style='cursor:pointer;' class='listStyle'>"+
"<div class='pic_name'>"+
"<img class='pic' src='images/blue_velvet_003.png'' /> "+
"</div>"+
"<div class='file_name'>"+
"<img class='file_pic' src='images/file.png' align='bottom'/> <font class='word_color'>"+ "aName"+ "</font>"+
"</div>"+
"</div>");
//alert($("#root").html())
});

//添加奇偶事件
// $(".pic_name").toggle(openDiv,closeDiv);
$(". pic_name").click(function(){
alert("hi")
});
function openDiv(){
alert("aa")
var temp_src = $(this).children(".pic").attr("src");
alert("temp_src=="+temp_src);
//if()
}
function closeDiv(){
alert("close")
}
});
</script>
</head>

<body>
<div id="tree">
<!--树-->
<div id="root">
</div>
</div>
</body>
</html>


我想问我的 $(". pic_name").click(function(){
alert("hi")
});怎么没有反应啊

而且奇偶事件也没有响应怎么回事啊
难道是我动态生成的问题?原来也是这样啊
...全文
115 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
cs0802 2009-12-27
  • 打赏
  • 举报
回复
版主,我劝你还是改用id好了啊
edielei 2009-12-27
  • 打赏
  • 举报
回复

$(".style1").click(function(){
$("#root").append(" <div style='cursor:pointer;' class='listStyle'><div class='pic_name'>"+
" <img class='pic' src='images/blue_velvet_003.png'' /> "+
" </div><div class='file_name'>"+
" <img class='file_pic' src='images/file.png' align='bottom'/>  <font class='word_color'>"+ "aName"+ " </font>"+
" </div></div>");
//alert($("#root").html())
$(".pic_name").click(function(){
alert("hi");
});
});
梅雪香 2009-12-27
  • 打赏
  • 举报
回复
遇到问题debug一下就能找到问题了
jQuery虽然方便,但也会隐藏很多可能的错误,不建议新手赖以生存

alert($('. pic_name').size());

试试
passself 2009-12-26
  • 打赏
  • 举报
回复
没有牛一点的人吗?
myeclipse0123 2009-12-26
  • 打赏
  • 举报
回复
楼主不可以在click事件中追加事件,这样是不可以的,最好写在函数中
yjcel1988 2009-12-24
  • 打赏
  • 举报
回复
可能是全半角问题吧
xmliy 2009-12-23
  • 打赏
  • 举报
回复
$(". pic_name")改为$(".pic_name")试试

87,955

社区成员

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

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