Php jquery类,打开两个相同的
好的,我们有一个mySQL while循环,为某个结果回显div 这是我们的代码:Php jquery类,打开两个相同的,php,javascript,jquery,mysql,Php,Javascript,Jquery,Mysql,好的,我们有一个mySQL while循环,为某个结果回显div 这是我们的代码: <div class="post"> <p>hello World</p> <div class="contentSlide"> <p>Members image on left and comments on the right. Date floated on right, and link to user.</p>
<div class="post">
<p>hello World</p>
<div class="contentSlide">
<p>Members image on left and comments on the right. Date floated on right, and link to user.</p>
<br />
<div class="contact">
<h3>Post a comment below</h3>
<p>My <label class="agentsHcard">Listings</label> <small>Only displays for logged in</small></p>
<form>
<input type="text" READONLY></input><br />
<textarea id="testTextarea" class="" type="text" name="comment" rows="3" style="background: none repeat scroll 0% 0% rgb(255, 255, 255); border: 1px solid rgb(51, 153, 255);"></textarea><br />
<div style="float:right;margin-right:40px;">
<button id="buttonsend" class="medium pink button" value="submit" name="submit" type="submit">Add Comment</button>
</div>
</form>
<br />
</div>
</div>
<div id="button" class="open">Comments(6) ▼</div>
</div>
你好,世界
成员图片在左边,评论在右边。日期浮动在右边,并链接到用户
在下面发表评论
我的列表仅在登录时显示
添加注释
评论(6)和#x25bc;
基本上,每个结果在我们的数据库中都有一个唯一的ID,例如:1、2、3、4、5
$(document).ready(function(){
reply=false;
$(".close").live('click',function(){
if(reply!==true){
$(".contentSlide, #contact").slideUp();
$(this).html("Comments(6) \u25bc").removeClass("close").addClass("open");
}
});
$(".open").live('click',function(){
$(".contentSlide").slideDown();
$(this).html("Close \u25b2 <span style='float:right;' onclick='reply=true;' class='reply' >Post a <a href='javascript:void(0);'>comment</a></span>").removeClass("open").addClass("close");
});
$(".reply").live('click',function(e){
$("#contact").slideDown(function(){reply=false;});
$("#button").html("Post and Close \u25b2").removeClass("open").addClass("close");
});
})
$(文档).ready(函数(){
答复=假;
$(“.close”).live('click',function(){
如果(回复!==true){
$(“.contentSlide,#contact”).slideUp();
$(this.html(“Comments(6)\u25bc”).removeClass(“close”).addClass(“open”);
}
});
$(“.open”).live('click',function(){
$(“.contentSlide”).slideDown();
$(this.html(“Close\u25b2 Post a”).removeClass(“open”).addClass(“Close”);
});
$(“.reply”).live('click',函数(e){
$(“#联系人”).slideDown(函数(){reply=false;});
$(“#按钮”).html(“发布并关闭\u25b2”).removeClass(“打开”).addClass(“关闭”);
});
})
我们正在寻找一种方法来实现这一点,以便为每个div提供一个唯一的ID,该ID被传递给javascript并打开相关的div
目前,如果我们有两个这样的结果,当单击open类时,这两个结果都会打开(显然)
我们知道如何通过复制JS并为每个JS提供一个特殊的ID来实现这一点,但我们正在寻找一种更干净的方法,只使用一次JS并使其全球化
我们怎样才能使它只包含一段javascript,而它使用的是一个ID?例如:
<div class="contentSlide" id="4">
谢谢。你可以试试类似的东西
$('.openthis').click(function(){
$(this).slideToggle();
});
在一个半无关的注释中,ID必须以字母开头 如果您想要一段Javascript,那么id可能不是解决问题的方法。为了对与单击的元素相关的DOM元素进行操作,您可能希望使用相对遍历函数(如“最近”(selector))向上导航到当前目标的“.post”div,然后向下遍历到要操作的元素:
$(".close").live('click',function(){
if(reply!==true){
$(this).closest(".post").children(".contentSlide, #contact").slideUp();
$(this).html("Comments(6) \u25bc").removeClass("close").addClass("open");
}
});
如果使用基于Id的机制,则可能需要执行一些字符串操作,并使元素Id为带有前缀/后缀的原始Id(即按钮4、联系人4等)创建一个函数,该函数接受JQuery项作为其参数,并将相关操作绑定到它。然后使用选择器查找与该类匹配的所有项目,并将
每个
与该函数一起使用