我想知道如何编辑draggable中的文本而不编辑其他draggables这是我的代码我可以添加多个带有文本的draggbales但我想编辑单个draggables而不更改其他draggables如果你需要更多信息请问
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script><script src="//cdnjs.cloudflare.com/ajax/libs/knockout/2.3.0/knockout-min.js"></script><link rel="stylesheet"
href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<link rel="stylesheet"
href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>var z = 1; //value to make div overlappable
$('#addText').click(function (e) {
/** Make div draggable **/
$('<div />', {
class: 'ui-widget-content',
appendTo: '.container',
draggable: {
containment: 'parent',
start: function( event, ui ) {
$(this).css('z-index', ++z);
}
}
});
});
$(document).on("dblclick", '.text', function()
{
$(this).hide(); $(this).closest('.item').find('.edit_text').val($(this).text()).show();
});
$(document).on("click", ".edit_text", function()
{
return false;
});
$(document).on("click", function()
{
var editingText = $('.edit_text:visible');
if (editingText.length)
{
editingText.hide();
editingText.closest('.item').find('.text').text($(editingText).val()).show();
}
});
ko.bindingHandlers.draggable={
init: function(element, valueAccessor, allBindingsAccessor, viewModel) {
$(element).draggable();
}
};
var vm=function(){
var self=this;
self.items=ko.observableArray();
self.textContent = ko.observable('');
self.init=function(){
self.items([]);
}
self.remove=function(item){
console.log(item);
self.items.remove(item);
}
self.addNew = function() {
self.items.push( self.textContent() );
self.textContent('');
}
self.init();
}
ko.applyBindings(new vm());
</script>
<script>
$('.thumbs img').click(function() {
var thmb = this;
var src = this.src;
$(thmb).parent('.thumbs').prev('.bottlesWrapper').find('img').fadeOut(400,function(){
thmb.src = this.src;
$(this).fadeIn(400)[0].src = src;
});
});
$("#fs").change(function() {
//alert($(this).val());
$('.item').css("font-family", $(this).val());
});
$("#size").change(function() {
$('.item').css("font-size", $(this).val() + "px");
});
$('.foo').click(function(){
$('.item').css("color", $(this).attr('data-color'));
});
</script>
<style>.item{
width: 200px;
height: 200px;
padding: 0.5em;
background:transparent;
z-index: 1;
display:block;
}
.edit_text
{
display: none;
}
.fix_backround
{
background-color: transparent;
}
.container {
width: 500px;
height: 500px;
border: 2px solid;
position: relative;
overflow: auto;
}
</style><style>
.thumbs img{
margin:3px;
width:50px;
float:left;
}</style>
<style>
.bottlesWrapper img{
margin:3px;
width:400px;
float:left;
}</style>
<style>#main { border:1px solid #eee; margin:20px; width:410px; height:220px;}
</style>
<style type="text/css" media="screen">
.transparent { background:transparent }
</style>
<style>.foo {
float: left;
width: 20px;
height: 20px;
margin: 5px;
border: 1px solid rgba(0, 0, 0, .2);
}
.white {
background: #FFFFFF;
}
.yellow {
background: #FAFF38;
}.black {
background: #000000;
}
</style><style> #mainTarget{
width:30px;
height:20px;
position:relative;
top:100px;
left:25%
}
.mainTarget{position:absolute; width:25px; height:25px;}
#target{
position:absolute;
height:25px;
width:25px;
background:url(http://files.softicons.com/download/system-icons/human-o2-icons-by-oliver-scholtz/png/128x128/actions/object-rotate-left.png) no-repeat top center #ffffff;
background-size:100%;
cursor:pointer;
z-index:1;
top:1;
right:1;
}
</style>
<form method="post" action="<?php echo $PHP_SELF;?>">
<div id="colour" >
<div class="foo white" data-color="#FFFFFF"></div>
<div class="foo black" data-color="#000000"></div>
<div class="foo yellow" data-color="#FAFF38"></div>
</div>
<select id="fs">
<option value="Agency FB">Agency FB</option>
<option value="Algerian">Algerian</option>
<option value="AR Berkley">AR Berkley</option>
<option value="AR Blanca">AR Blanca</option>
<option value="AR Bonnie">AR Bonnie</option>
<option value="AR Carter">AR Carter</option>
<option value="AR Cena">AR Cena</option>
</select>
</form>
<textarea data-bind="value: textContent" Placeholder="Type text to append"></textarea>
<button data-bind="click: addNew">Generate New Div</button>
<div class="container">
<div data-bind="foreach:items" class="fix_backround">
<div href="#" class="item" data-bind="draggable:true,droppable:true">
<span data-bind="click:$parent.remove">[x]</span><br/><br/>
<center><span class="text" data-bind="text:$data"></span><input class="edit_text"/></center>
</div>
</div>
</div>