我正在使用Jquery UI Draggable。 我试图避免一旦接收到该项目的div达到限制就丢弃物品。如下所示,这是我的代码。
import random
x = input("Enter a number: ")
for i in range(len(x)):
randomGuess = random.randrange(1,10)
while randomGuess != int(x[i]):
print('Digit',i,'not found')
randomGuess = random.randrange(1,10)
print('Digit',i,'found:',x[i])
JS小提琴示例:http://jsfiddle.net/r1Lnxby9/
答案 0 :(得分:1)
修改,更新
尝试从ondragstart="drag(event)"
移除draggable="true"
,html
,drag
js
未显示tolerance:"touch"
在.droppable()
选项设置$("> li", this).length
;将count
替换为$("#grid-list").each()
,>=
; >
的{{1}} 1
如果预期结果是.droppable()
元素中event.preventDefault()
元素的最大值;在event.stopPropagation()
事件
over
, $("#list-albuns, #grid-list").sortable({
connectWith: ".connectedSortable"
}).disableSelection();
$("#grid-list").droppable({
tolerance: "touch",
over: function(event, ui) {
if ($("> li", this).length >= $(this).data("albumlist")) {
event.preventDefault();
event.stopPropagation();
alert("limit");
}
}
});
ul li {
display: inline-block;
list-style: none;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js">
</script>
<ul id="list-albuns" class="connectedSortable ui-sortable">
<li id="0" class="ui-sortable-handle">
<input type="hidden" name="albumId[]" value="0">
<img id="dragimg0" height="126" width="126" src="http://userserve-ak.last.fm/serve/126/51552793.png" alt="Appetite for Destruction">
</li>
<li id="2" class="ui-sortable-handle">
<input type="hidden" name="albumId[]" value="2">
<img id="dragimg2" height="126" width="126" src="http://userserve-ak.last.fm/serve/126/97176319.png" alt="Use Your Illusion II">
</li>
<li id="3" class="ui-sortable-handle">
<input type="hidden" name="albumId[]" value="3">
<img id="dragimg3" height="126" width="126" src="http://userserve-ak.last.fm/serve/126/89710469.png" alt="40 Seasons - The Best Of Skid Row">
</li>
<li id="5" class="ui-sortable-handle">
<input type="hidden" name="albumId[]" value="5">
<img id="dragimg5" height="126" width="126" src="http://userserve-ak.last.fm/serve/126/56005467.jpg" alt="Danger Danger">
</li>
<li id="6" class="ui-sortable-handle">
<input type="hidden" name="albumId[]" value="6">
<img id="dragimg6" height="126" width="126" src="http://userserve-ak.last.fm/serve/126/85595741.jpg" alt="Screw It [Italy Bonus Tracks]">
</li>
<li id="7" class="ui-sortable-handle">
<input type="hidden" name="albumId[]" value="7">
<img id="dragimg7" height="126" width="126" src="http://userserve-ak.last.fm/serve/126/90791541.jpg" alt="Detonator">
</li>
</ul>Drop Here:
<ul id="grid-list" data-albumlist="1" class="connectedSortable" style="width:500px; height:200px;display:block; border:2px solid black;"></ul>
&#13;
const string serviceUri = "http://localhost:54123/MyService";
var host = HostFactory.New(configurator =>
{
configurator.Service<WcfServiceWrapper<MyServiceClass, IMyServiceClass>>(serviceConfigurator =>
{
serviceConfigurator.ConstructUsing(x =>
new WcfServiceWrapper<MyServiceClass, IMyServiceClass>("MyService", serviceUri));
serviceConfigurator.WhenStarted(service => service.Start());
serviceConfigurator.WhenStopped(service => service.Stop());
});
configurator.RunAsLocalSystem();
configurator.SetDescription("Runs My Service.");
configurator.SetDisplayName("MyService");
configurator.SetServiceName("MyService");
});
&#13;
jsfiddle http://jsfiddle.net/r1Lnxby9/2/