I have a list which can be sortable. I'm using jQuery UI with widget, mouse, position, sortable addons.
CSS:
#sortable{
width : 550px;
display: inline-block;
}
#sortable li, #add {
width : 550px;
margin : 5px;
padding : 5px;
height : 50px;
}
#sortable li img.social-icon, #sortable li img.drag-cursor {
width: 40px;
height : 40px;
float : left;
}
#sortable li img.social-icon {
margin-right : 5px;
}
#sortable li img.drag-cursor {
margin-left : 5px;
cursor : move;
}
#sortable li input {
height:40p开发者_开发问答x;
width:450px;
line-height: 45px;
float:left;
}
#add {
cursor : pointer;
text-align: center;
line-height: 45px;
}
.ui-state-highlight { height: 50px; line-height: 50px; }
HTML:
<div id="dash-wrapper">
<ul id="sortable">
<li class="ui-state-default">
<img src="images/social/twitter.png" class="social-icon" />
<input type="text" value="textt" name="user-media-link[]" class="user-media-link">
<input type="hidden" name="social-media-type" value="1">
<img src="images/drag.png" class="drag-cursor">
</li>
<li class="ui-state-default">
<img src="images/social/facebook.png" class="social-icon" />
<input type="text" value="textt" name="user-media-link[]">
<input type="hidden" name="social-media-type" value="1">
<img src="images/drag.png" class="drag-cursor">
</li>
<li class="ui-state-default">
<img src="images/social/rss.png" class="social-icon" />
<input type="text" value="textt" name="user-media-link[]">
<input type="hidden" name="social-media-type" value="1">
<img src="images/drag.png" class="drag-cursor">
</li>
</ul>
<div class="ui-state-default" onCLick="addNewSocial(); return false;" id="add">ADD</div>
</div>
Script:
$(function() {
$("#sortable").sortable({
placeholder: "ui-state-highlight"
});
$("#sortable").disableSelection();
});
function addNewSocial() {
$("#sortable").append('<li class="ui-state-default"><img src="" width="100" height="100" /> <input type="text" value="textt" name="user-media-link[]"><input type="hidden" name="social-media-type" value="1"></li>');
}
It's working very well, but I can't type anything to inputs. I can reach them only via TAB button. When I click them, nothing happens. You can see a live example.
I was read all questions which related with this question, but i couldn't find right answer.
W3 Validation is OK There isn't any error on Firebug Operation System : Ubuntu 11.04 Browser : Firefox
This happens because you have $("#sortable").disableSelection();
. Remove it and will work ok.
http://jsfiddle.net/KbBnu/1/
If would like to prevent text selection but continue to use inputs at the same time, you should try this
$('body *').not(':has(input)').not('input').disableSelection();
Just do:
$( "#sortable_container_id input").click(function() { $(this).focus(); });
and replace sortable_container_id
with the id of the element that is the container of all "sortable" elements.
精彩评论