jquery - How to get editable text value from bootstrap editable plugin -


I am using it for editing text. I want to change the text of two edited fields, respectively, to change the text "Lesson 1", "Lesson 2" How can I do this?

I tried with this script:

  var title = $ ('. Edit_text'). Editable ('getValue'); $ ('Name-list p'). Html (title);   

>

Demo:

HTML:

  & lt; Div & gt; & Lt; A href = "# text1" class = "edit_text" & gt; Name me & lt; / A & gt; & Lt; / Div & gt; & Lt; Div & gt; & Lt; A href = "# text2" class = "edit_text" & gt; Nominated Me & lt; / A & gt; & Lt; / Div & gt; & Lt; Div class = "name-list" & gt; & Lt; P id = "text1" & gt; Lesson 1 & lt; / P & gt; & Lt; P id = "text2" & gt; Lesson 2 & lt; / P & gt; & Lt; / Div & gt;  

JS:

  $ Fn.editable.defaults.mode = 'inline'; $ ('.edit_text'). Editable ({type: 'text', success: function (k, val) {var id = $ (this) .attr ("href"); $ ('name-list' + id) .html (val) ;}});  

UPDATE

tells me how it works. I apologize for not doing this before, it works:

We first make HTML. As you can see, the anchor tag & lt; A & gt; There is a class of edit_text in so that we can use it to attach the attachment . , But they also place IDs in their href attributes.

In jQuery,

  • We use Bootstrap .usable method ( ), < / P>

  • We set the "Inline" default mode so that all edits become inline by default popup path by $ .fn.editable.defaults.mode = 'inline'; .

  • We attach to . Editable methods for all elements holding .edit_text , and we give it the necessary options. $ ('.edit_text'). Editable ({.})

  • One of those options is callback success which happens when editing is completed.

  • When success callback is executed, this index returns k and the value val success of the current element: work (k, val)

  • We will catch the code of href > ID variable var id = $ (this) .attr ("href");

  • We look at the element with the class of name code, and ID Find out. $ ('.name-list' + id)

  • Finally we insert the value val from the callback < Em>

Hope it helps.


Comments