JQuery问题,很纠结!!

lanmolsz 2010-06-04 05:55:54
<html>
<head>
<title>-- Chat --</title>
<SCRIPT type="text/javascript" src="jquery-1.4.2.js">
</SCRIPT>
</head>
<body>
<h3>Chat Frame</h3>
<div style="width: 950px;">
<hr />
<table width="100%">
<tr>
<td width="15%">
<table width="100%" align="center">
<tr><td width="100%"><div id="departments">
<a href="#" onclick="showStaffList('department3')"><h2>department3</h2></a>
<div style="display:none" id="department3">
<a href="#" id="staff9" ondblclick="showChatWindow('staff9')">Benjamin</a>
<br>
<a href="#" id="staff10" ondblclick="showChatWindow('staff10')">Barton</a>
<br>
<a href="#" id="staff11" ondblclick="showChatWindow('staff11')">Bartholomew</a>
<br>
<a href="#" id="staff12" ondblclick="showChatWindow('staff12')">Blithe</a>
</div>
</div></td></tr>
</table>
</td>
<td width="85%" background="images8.jpg">
<DIV id="condiv" style="width: 800px">
</DIV>
</td>
</tr>
</table>
<hr />
<div style="width: 100%" id="chatWindows"><h1>there is chat window</h1></div>
</body>
<script type="text/javascript">
function showStaffList(id){
var obj = $("#"+id);
if(obj.css("display")=="none"){
obj.css('display','block');
}else{
obj.css("display","none");
}
}
function showChatWindow(id){
var windowId = "#"+id+'window';
var obj = $(windowId);
if(obj.length>0){
if(obj.css("style")=="none"){
obj.css("style","block");
}else{
alert("chat window was opened");
}
}else{
createChatInterfase(id);
}
}
function createChatInterfase(id){
var windowId = id+'window';
var histroyId = id+'history';
var contentId = id+'content';
var windowDiv = $("#chatWindows");
var newDIV = $("<div>");
newDIV.attr("id",windowId);
newDIV.css({width: "305px","background-color": "#ccee99"});
var subDIV = $("<div>");
subDIV.attr("id",histroyId);
subDIV.css({width: "300px",height:" 220px","background-color":"#eeeedd"});
var text = $("<textarea>");
text.attr({cols:"26",rows:"2",id:contentId});
var closeButton = $("<input>");
closeButton.attr({type:"button",value:"close"});
closeButton.bind("click",{windowId:windowId},hideChatWindow);
var sendButton = $("<input>");
sendButton.attr({type:"button",value:"send"});
newDIV.append(subDIV);
newDIV.append(text);
newDIV.append(closeButton);
newDIV.append(sendButton);
windowDiv.append(newDIV);
}
function hideChatWindow(windowId){
alert(windowId+"你大爷的!!");
var obj = document.getElementById(windowId);
obj.style.display="none";
//var obj = $("#"+windowId);
//obj.css("display","none");
}

</script>
</html>


<!--很莫名其妙的错误,我很纠结,hideChatWindow的不到值,他在createChatInterfase这个方法里面被动态生成,动态绑定事件,但是我对比很多次都没找到自己哪里写错了-->
...全文
112 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lanmolsz 2010-06-07
  • 打赏
  • 举报
回复
xiexie
yliu0 2010-06-05
  • 打赏
  • 举报
回复

<html>
<head>
<title>-- Chat --</title>
<SCRIPT type="text/javascript" src="jquery-1.4.2.js">
</SCRIPT>
</head>
<body>
<h3>Chat Frame</h3>
<div style="width: 950px;">
<hr />
<table width="100%">
<tr>
<td width="15%">
<table width="100%" align="center">
<tr><td width="100%"><div id="departments">
<a href="#" onclick="showStaffList('department3')"><h2>department3</h2></a>
<div style="display:none" id="department3">
<a href="#" id="staff9" ondblclick="showChatWindow('staff9')">Benjamin</a>
<br>
<a href="#" id="staff10" ondblclick="showChatWindow('staff10')">Barton</a>
<br>
<a href="#" id="staff11" ondblclick="showChatWindow('staff11')">Bartholomew</a>
<br>
<a href="#" id="staff12" ondblclick="showChatWindow('staff12')">Blithe</a>
</div>
</div></td></tr>
</table>
</td>
<td width="85%" background="images8.jpg">
<DIV id="condiv" style="width: 800px">
</DIV>
</td>
</tr>
</table>
<hr />
<div style="width: 100%" id="chatWindows"><h1>there is chat window</h1></div>
</body>
<script type="text/javascript">
function showStaffList(id){
var obj = $("#"+id);
if(obj.css("display")=="none"){
obj.css('display','block');
}else{
obj.css("display","none");
}
}
function showChatWindow(id){
var windowId = "#"+id+'window';
var obj = $(windowId);
if(obj.length>0){
if(obj.css("style")=="none"){
obj.css("style","block");
}else{
alert("chat window was opened");
}
}else{
createChatInterfase(id);
}
}
function createChatInterfase(id){
var windowId = id+'window';
var histroyId = id+'history';
var contentId = id+'content';
var windowDiv = $("#chatWindows");
var newDIV = $("<div>");
newDIV.attr("id",windowId);
newDIV.css({width: "305px","background-color": "#ccee99"});
var subDIV = $("<div>");
subDIV.attr("id",histroyId);
subDIV.css({width: "300px",height:" 220px","background-color":"#eeeedd"});
var text = $("<textarea>");
text.attr({cols:"26",rows:"2",id:contentId});
var closeButton = $("<input>");
closeButton.attr({type:"button",value:"close"});
closeButton.bind("click",{windowId:windowId},hideChatWindow);
var sendButton = $("<input>");
sendButton.attr({type:"button",value:"send"});
newDIV.append(subDIV);
newDIV.append(text);
newDIV.append(closeButton);
newDIV.append(sendButton);
windowDiv.append(newDIV);
}
function hideChatWindow(event){
var windowId = event.data.windowId;
alert("window id: " + windowId);
var obj = document.getElementById(windowId);
obj.style.display="none";
//var obj = $("#"+windowId);
//obj.css("display","none");
}

</script>
</html>
yliu0 2010-06-05
  • 打赏
  • 举报
回复

function hideChatWindow(event){
var windowId = event.data.windowId;
alert("window id: " + windowId);
var obj = document.getElementById(windowId);
obj.style.display="none";
//var obj = $("#"+windowId);
//obj.css("display","none");
}
lanmolsz 2010-06-04
  • 打赏
  • 举报
回复
没什么区别,那都没区别。我也不知道怎么回事
hnsxldj 2010-06-04
  • 打赏
  • 举报
回复
你第一段代码为什么不用第二段代码中的方式,如

function hideChatWindow(event){
windowId = event.data.windowId;
alert(windowId+"你大爷的!!");
var obj = document.getElementById(windowId);
obj.style.display="none";
//var obj = $("#"+windowId);
//obj.css("display","none");
}
hoojo 2010-06-04
  • 打赏
  • 举报
回复
windowid你传了没。
closeButton.bind("click",{windowId:windowId},hideChatWindow);
这个方法执行了没,你换其他的方法试试
lanmolsz 2010-06-04
  • 打赏
  • 举报
回复
<html>
<head>
<title></title>
<SCRIPT type="text/javascript" src="../js/jquery-1.4.2.js">
</SCRIPT>
</head>
<body>

<div id="xiaowang" style="width: 345px;background-color: #ccee99;">
<h1>Hello</h1>
</div>
<DIV id="IronMan">
<h1>I am IronMan!!</h1>
</DIV>
<input type="button" value="test" id="button1" >
<input type="button" value="add" id="b1" onclick="method()">
</body>
<script type="text/javascript">
function handler(event) {
alert(event.data.foo);
}
function method(){
var foo = "fuck";
$("#button1").bind("click", {foo: foo}, handler);
}
</script>
</html>
还有一个跟这个类似。但是他可以正常运行

87,901

社区成员

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

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