jquery add new div onclick

Habe ich eine Liste von div

<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- 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>
         </div>
     </div>
</li>

Möchte ich noch hinzufügen eines neuen div auf div auf. Ich schrieb jquery-codes, aber es funktioniert nicht.

function addcommentdiv () {
    var NewContent = '<div class=""><input name="name" type="text" id="name" size="20" value="" style="height:20px; margin-top:10px; width:480px;margin-left:90px; font-size:14px;" /></div>'
    $('.comment-body').click(function () {

        var index2 = $('.comment-body').index(this);
        if (NewContent != '') {
            $('.comment-body').eq(index2).after(NewContent);
            NewContent = '';

        }
        else {
            $('.comment-body').eq(index2).next().toggle();

        }

    });

};

Warum es nicht funktioniert oder wie kann ich einen neuen div geklickt div unten (als twitter-reply)? Bevor ich schrieb einige code. Es funktioniert, aber es gab ein problem: es war Arbeit für ein div nur.

  • Schauen Sie in api.jquery.com/append
  • wer ruft addcommentdiv ()
  • müssen Sie rufen Sie addcommentdiv auf dom-ready wie $(function(){ addcommentdiv(); }). Außer, dass es gut aussieht jsfiddle.net/arunpjohny/7gyrB/1
  • danke, aber wie gesagt es funktioniert nur bei 1 div. Ich aktualisiert, können Sie das überprüfen ? link
  • checkout jsfiddle.net/arunpjohny/7gyrB/4
  • ist es großartig. Danke.Können Sie schreiben als Antwort.Ich will es markieren.Nochmals vielen Dank Kumpel
  • aktualisiert, sobald eine Antwort

InformationsquelleAutor serdar | 2013-05-01
Schreibe einen Kommentar