简体   繁体   English

替换元素并单击返回旧元素

[英]Replace element and on click return the old element

I have following function: 我有以下功能:

datum.on('change', function(){
    var url = '<?php echo base_url()  ?>admin/admin_tvprogram .tvprogram > *';
    tvprogram.empty().load(url, {'datum':$(this).val()}, function(){
        var izmeni = $(this).find('a');
        izmeni.on('click', function(){
            var sat = $(this).parent().find('.sat'),
            sat_vrednost = sat.text(),
            naziv = $(this).parent().find('.naziv'),
            naziv_vrednost = naziv.text(),
            vrati = $(this).parent().append('<span class=vrati>Vrati</span>');

            var novi_sat = sat.replaceWith('<input type=text name=sat value=' + sat_vrednost + ' >' ),
            novi_naziv = naziv.replaceWith('<input type=text name=naziv value=' + naziv_vrednost + ' >' );

        });
    });
});

Everything is working fine, but I need one more functionality. 一切工作正常,但我需要其他功能。 When a user click on vrati (new appended span element), elements sat and naziv need to return to original form. 当用户单击vrati (新附加的span元素)时, satnaziv元素需要恢复为原始形式。 How can I do this? 我怎样才能做到这一点?

When load function is activated I get following HTML: 激活加载功能后,我得到以下HTML:

<ul>
    <li>
    <span class="sat">18:00</span>
    <span class="naziv">Opravka Traktora</span>
    <a data-id="2">Izmeni</a>
  </li>
</ul>

After izmeni is clicked I get following HTML: 单击izmeni后,我得到以下HTML:

<ul>
<li>
<input type="text" value="18:00" name="sat">
<input type="text" traktora="" value="Opravka" name="naziv">
<a data-id="2">Izmeni</a>
<span class="vrati">Vrati</span></li>
</ul>

You are saving the values of the elements right when the user clicks. 用户单击时,将立即保存元素的值。

Probably need to save the values before doing the load and then the same code in the on-click will restore them. 可能需要在加载之前保存这些值,然后单击时的相同代码将还原它们。

Populate your list input tables from variables that you define, and then apply the j query .text action to your sat and naziv giving them the parameter of that variable again when vrati is clicked 从定义的变量中填充列表输入表,然后将jquery .text操作应用于sat和naziv,在单击vrati时再次为它们提供该变量的参数

//the function textvalueToggle gets called on document load assigning the values to sat and naziv. //在文档加载时调用函数textvalueToggle,将值分配给sat和naziv。 Then a click listener is attached to vrati to call that same function reassigning the values 然后,将点击监听器附加到vrati,以调用相同的函数来重新分配值

    $(document).ready(function() {
           textvalueToggle();
           $('#vrati').click(textvalueToggle);
    });

    function textvalueToggle() {
       $('#sat').text('18:00');
       $('#naziv').text('Opravka Traktora');
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM