jQuery - 替换跨越父文本是删除span元素?

时间:2016-02-05 03:12:28

标签: javascript php jquery html smarty

我认为即将到来!我有它替换TD中的文本,但它也删除了TD中的其他元素,如跨度,反正只是为了替换文本?

更换前

session.clear()

用我的JS替换后

<td>
    <span alt="Expand the sublist of items" title="Expand the sublist of items" id="on_user_81257937_1" class="cm-combination-carts" onclick="Tygh.$.ceAjax('request', 'admin.php?dispatch=cart.cart_list&amp;user_id=81257937&amp;c_company_id=1', {result_ids: 'cart_products_81257937_1,wishlist_products_81257937_1', caching: true});"><span class="exicon-expand"></span></span>
    <span alt="Collapse the sublist of items" title="Collapse the sublist of items" id="off_user_81257937_1" class="hidden cm-combination-carts"><span class="exicon-collapse"></span></span>

    Unregistered customer        
</td>

期待什么

<td>James Murphy</td>

Smarty / JS

<td>
    <span alt="Expand the sublist of items" title="Expand the sublist of items" id="on_user_81257937_1" class="cm-combination-carts" onclick="Tygh.$.ceAjax('request', 'http://beanbags.ambientlounge.com/admin.php?dispatch=cart.cart_list&amp;user_id=81257937&amp;c_company_id=1', {result_ids: 'cart_products_81257937_1,wishlist_products_81257937_1', caching: true});"><span class="exicon-expand"></span></span>
    <span alt="Collapse the sublist of items" title="Collapse the sublist of items" id="off_user_81257937_1" class="hidden cm-combination-carts"><span class="exicon-collapse"></span></span>

    James Murphy       
</td>

1 个答案:

答案 0 :(得分:0)

解决方案是:

<script type="text/javascript">

    $(document).ready(function(){

        $('#off_user_{$customer.user_id}_1').parent().contents().last()[0].textContent="{$ac_firstname} {$ac_lastname}";

    });

</script>