I am creating a list & want to make its item sortable and editable. So i am doing it like this:
<ul id="ul_list">
<li><span contenteditable="true">A</span></li>
<li><span contenteditable="true">B</span></li>
<li><span contenteditable="true">C</span></li>
</ul>
$("#ul_list").sortable();
/
But if i use jquery ui sortable then my list item is losing focus for editing and that's why i am not able to edit them.
So please suggest how can i do this?
I am creating a list & want to make its item sortable and editable. So i am doing it like this:
<ul id="ul_list">
<li><span contenteditable="true">A</span></li>
<li><span contenteditable="true">B</span></li>
<li><span contenteditable="true">C</span></li>
</ul>
$("#ul_list").sortable();
http://jsfiddle/7jzVa/
But if i use jquery ui sortable then my list item is losing focus for editing and that's why i am not able to edit them.
So please suggest how can i do this?
Share Improve this question asked Sep 27, 2013 at 21:01 PeeyushPeeyush 4,86817 gold badges66 silver badges92 bronze badges 1- stackoverflow./questions/2995329/… gives a good solution~ – CoolGuy Commented Jan 17, 2014 at 2:32
3 Answers
Reset to default 4We could make use of the cancel option provided by jquery sortable
$("#ul_list").sortable({cancel: 'span'});
#ul_list li{
border:1px solid red;
list-style-type:none;
}
<ul id="ul_list">
<li><span contenteditable="true">A</span></li>
<li><span contenteditable="true">B</span></li>
<li><span contenteditable="true">C</span></li>
</ul>
Clicking on the text will make it editable. Can be sorted by clicking anywhere else
Finally i did it like this;
On mousedown event i applied the sortable() so that user can sort elements by dragging them,
On click i destroyed the sortable .sortable("destroy"). So now the elements are editable.
I also have the same problem and I fixed by the following code:
$('#ul_list').on("mousedown",function(){
$("#ul_list").sortable();
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744718547a4589768.html
评论列表(0条)