Jump to content
php.lv forumi
  • 0

Tabulas td elementi -> input lauki


Salv

Question

5 answers to this question

Recommended Posts

  • 0

http://jsfiddle.net/4uV4X/

<table>
    <tr><td>Hello</td><td>world</td></tr>
    <tr><td>Hello</td><td>world</td></tr>
</table>
$('table').on('click','td',function(){
    if ($(this).has('input').length) return;
    var val=$(this).html();
    $(this).html($('<input>').val(val));
    $('input',this)
        .focus()
        .on('focusout',function(){
            $(this).parent().html($(this).val());
        });
});
Link to comment
Share on other sites

  • 0

Konkrētās ierakstā definētās problēmas risinājums: http://jsfiddle.net/a4VXk/

$('tr').append('<td><button class="btn-edit">edit</button></td>');
$('table').on('click','.btn-edit',function(){
    $this=$(this);
    $this.parents('tr').find('td').not($this.parent()).each(function(){
        $(this).html($('<input>').val($(this).html()));
    });
    $this.parent().html('<button class="btn-ok">ok</button>');
});
$('table').on('click','.btn-ok',function(){
    $this=$(this);
    $this.parents('tr').find('td').not($this.parent()).each(function(){
        $(this).html($('input',this).val());
    });
    $this.parent().html('<button class="btn-edit">edit</button>');
});
Link to comment
Share on other sites

  • 0

Skatoties pēc lietotāja codez pēdējā piemēra, kā es šajā vietā:

$(this).html($('<input>').val($(this).html()));

varētu padot līdzi arī "name" atribūtu?

 

Un otrs, ne mazāk svarīgais jautājums, kā būtu iespējams skripta beigās uztaisīt "Cancel" pogu (teiksim "OK" pogas vietā), kas atceltu ieraksta labošanu, atgriežot ierakstu sākotnējā izskatā?

Edited by Salv
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...