Jeditable - Activate edit of X by clicking on Y

后端 未结 4 1265
野趣味
野趣味 2020-12-11 01:36

I\'m trying to use Jeditable as an inline editing solution.

The default behavior (click on the element to edit it) works quite well, but I would like to activate an

相关标签:
4条回答
  • 2020-12-11 01:45

    You can place this code in click function of another element. example:

    HTML:

    <a class="clickme">Click me to edit</a>
    <div class="edit">Edit Me!</div>
    

    jQuery:

    $(document).ready(function() {
    $("a.clickme").click(function(){
         $('.edit').editable('http://www.example.com/save.php');
    });
    });
    
    0 讨论(0)
  • 2020-12-11 01:49

    Ok, Ata's answer didn't quite work but it did set me on the right path:

    $(document).ready(function() {
        $('.edit').editable('http://www.example.com/save.php');
        $("a.clickme").click(function(){
              $('.edit').click();
       });
    });
    
    0 讨论(0)
  • 2020-12-11 01:54

    I've combined the powers of the previous two responses to target the next editable element like so:

    /* Find and trigger "edit" event on next Jeditable instance. */ $(".edit_trigger").livequery( 'click', function() { $(this).next().click(); });

    0 讨论(0)
  • 2020-12-11 01:56

    Above code is not quite correct either. It triggers click event on ALL Jeditable instances.

    There are many ways to do it and it all depends on your HTML, but for example if you have following HTML:

    <div class="edit" id="unique_id">Editable text</div> 
    <a href="#" class="edit_trigger">Edit me!!</a>
    

    Then you can use following JavaScript:

    /* Bind Jeditable instances to "edit" event. */
    $(".edit").editable("http://www.example.com/save.php", {
        event     : "edit"
    });
    /* Find and trigger "edit" event on correct Jeditable instance. */
    $(".edit_trigger").bind("click", function() {
        $(this).prev().trigger("edit");
    }); 
    
    0 讨论(0)
提交回复
热议问题