-->

JQuery JEditable - How to Disable on click editing

2019-02-05 01:07发布

问题:

I was wondering if you can stop text being editable on click? I have a separate edit button to make the text editable and that's the only way that I want the user to be able to edit the text, so want to turn off the on click editing?

Any ideas?

回答1:

Britt is right, add a custom event, and trigger it with a button for example. Here is some code to explain it:

The custom event:

$('#id').editable('http://www.example.com/save.php', {
    event : 'custom_event'
});

And the trigger:

<button onclick="$('#id').trigger('custom_event');">click to trigger</button>


回答2:

There's an undocumented option event that you can use when you create your jEditable fields.

(It's not actually undocumented but it's just mentioned off-hand in one sentence on the jEditable docs page.)

You can use it to change the event that makes the field editable. You can use any jquery event, even custom events.

For example, on my project I created an edit.mode event that makes the field editable which I can then trigger however I like, with a button, a hotkey, whatever.