2

シナリオは、div コンテンツを取得し、それを変更して別の div に挿入したいというものです。以下のコード:

$("#loupe").live("click",function(){
    $('#divBody').empty();
    $('#divTitle').empty();
    var title = $(this).closest('div').find('.stepTitle').text();
    var divContent = $(this).closest('div').html();
    // code to modify the content to be inserted in the modal 
    $('#divBody').append(divContent);
    $('#divTitle').append(title);
    $('#div').modal({ dynamic: true });
});

詳しくは、最初の div には、コンテンツを新しい div に挿入する前に削除したいタイトルが含まれているため、新しい div にはタイトルのないコンテンツが含まれている必要があります

<div>
    <h4 class="StepTitle">Planing des congés pour le service de <%=service.getNomService() %> au <%=month%> / <%=year%>   
        <span style="float: right;">
            <i class="icon-white icon-search" style="cursor: pointer;" id="loupe"> </i>  
            <i class="icon-white  icon-remove" style="cursor: pointer;" onclick="$(this).closest('div').remove();"> </i> 
        </span>  </h4>  
    <table border="1" style="border-color: gray;">
    </table> 
</div>

// * ** * ** * **** *コンテンツが挿入される div

<div id="div" class="modal hide fade" tabindex="-1" role="dialog"
        aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h3 id="divTitle">
            //here the title
        </h3>

    </div>
    <div id="divBody" class="modal-body">
        here the other content
    </div>
    <div  class="modal-footer">
        <input type="button" class="btn" class="close" data-dismiss="modal" value="fermer">
    </div>
</div>  
4

1 に答える 1

1

jQuery を使用すると、ページのフラグメント (および XML) を操作できます。

メソッドを使用し.htmlて要素の HTML を変数に割り当てたら、次のように HTML を操作できます。

var html, withoutTitle;
html = $('#someDiv').html();
withoutTitle = $(html).remove('#title').html();
$('#someOtherDiv').html(withoutTitle);

このコードはまだテストしていないので、目的に合わせて少し調整する必要があるかもしれません。

于 2013-04-02T14:32:12.090 に答える