Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery使用.next()获取显示属性_Jquery_Css_Next - Fatal编程技术网

jquery使用.next()获取显示属性

jquery使用.next()获取显示属性,jquery,css,next,Jquery,Css,Next,我想得到一个div的css显示属性值。 我用的是这个密码 function addcommentdiv() { $('.comment-body').click(function () { var $this = $(this), $reply = $this.next('cevapla'); var cevapladisplay = $reply.css('display'); alert(cevapladisplay); });

我想得到一个div的css显示属性值。 我用的是这个密码

function addcommentdiv() {
    $('.comment-body').click(function () {
        var $this = $(this), $reply = $this.next('cevapla');
        var cevapladisplay = $reply.css('display');
        alert(cevapladisplay);
    });
};
但该代码返回“未定义”。如何获取$reply对象的显示属性

CSS代码

<li class="comment">

  <div class="comment-body" id="comment-body">
    <div class="comment-author vcard">
      <div class="lightbox-photo">
        <a class="image-overlay" href='<%# "Foto/profil/foto_buyuk/" + Eval("Yorum_Profil_Foto_Buyuk") %>' data-rel="prettyPhoto" title='<%# Eval("Yorum_UserName")%>'><img src='<%# "Foto/profil/foto_kucuk/" + Eval("Yorum_Profil_Foto_Kucuk") %>' alt='<%# Eval("Yorum_UserName")%>' class="avatar" /></a>
      </div>
      <cite class="fn"><asp:HyperLink ID="linkProfil" runat="server" Text='<%# Eval("Yorum_UserName")%>' NavigateUrl='<%# "~/profil.aspx?user_id="+Eval("User_ID") %>'></asp:HyperLink></cite>
      <cite class="fn-time"></cite> 
    </div>
    <p><%# Eval("Yorum_Text")%></p>
  </div>

  <!-- MORE CODE HERE -->      

  <div class="cevapla" id="cevapla" >
   <asp:TextBox ID="txtCevapla" runat="server"    CssClass="cevaplatextbox" ></asp:TextBox>
   <asp:Button ID="btnCevapla" runat="server" Text="Button" />
  </div>

</li>

  • 您必须使用选择器:

    var $this = $(this), $reply = $this.next('.cevapla');
    
    我不知道cevapla是什么,它是一门课吗?您可以通过执行以下操作来确定jQuery是否选择了元素:

    console.log($this.next(".cevapla").length);
    

    jQuery的
    next
    方法接受选择器作为参数

    作为原始帖子的后续,以下是固定代码:

    function addcommentdiv() {
        $('.comment-body').click(function () {
            var $this = $(this), $reply = $this.next('.cevapla');
            var cevapladisplay = $reply.css('display');
            alert(cevapladisplay);
        });
    }
    
    我删除了

    在一篇评论中,询问者还提到
    cevapla
    也是元素的ID。在这种情况下,如果ID是唯一的,则将赋值重写为
    $reply=$(“#cevapla”)
    更有意义。

    I更改了“.next”to“.find”。它正在工作(比.next慢一点)

    }


    addcommentdiv()

    div class=“cevapla”id=“cevapla”>cevapla是div id,css类比我使用id选择器给你的要快,因为它更快。@serdar你让每个人都猜到了。只需在问题中添加您的HTML,我们就可以给您正确的答案。:)我猜是
    $this.next('cevapla')未选择任何元素。从上到下调试,而不是相反。让我们看看你的HTML,OP。你得到了
    未定义的
    ,因为选择器不准确。你在
    .cevapla
    前面有一个额外的关闭
    标记,在这种情况下,你可以使用普通的
    .next()
    。@KevinB我更新了我的帖子:)$this.next('cevapla');正在选择元素。@serdar这没有任何意义。它不应该选择任何元素,因为您没有任何
    元素。owww非常抱歉:/It's working.您是对的,伙计。非常抱歉,非常感谢这并不能解决问题。我有一个div列表。所以我一直在使用。接下来,它只对一个div工作。HTML中的ID对于每个元素都应该是唯一的。如果不是唯一的,请使用类。我将更新我的答案。是的,但我有commentlist。我不能为所有列表项提供唯一的id。正如我所说,我使用了。next():如果每个评论都会重复使用,那么首先你不应该使用
    id=“cevapla”
    。我已经相应地更新了我的答案。
    function addcommentdiv() {
    $('.comment-body').click(function () {
        var $this = $(this), $reply = $this.find('.cevapla');
        var cevapladisplay = $reply.css('display');
        alert(cevapladisplay);
    });