此代码将在单击时从右到左添加列表中的项目。我们必须点击弹出图片才能移动。现在我期望做的是从json文件中获取元素,一旦我将文本移动到另一个框,它必须禁用该选择。用户必须无法再次单击它,换句话说,可以选择一个项目。但该项不得从第一个列表中删除。请帮忙。提前谢谢
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
<script type = "text/javascript" src = "js/jquery.js"></script>
<script type = "text/javascript" src = "js/jquery_ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<style>
#firstlist li:hover img {display: inline;}
#firstlist li:hover { background: #CCF5CC; }
#firstlist .ui-selected { background: #80B280; }
#firstlist { list-style-type: none;}
#firstlist li { margin: 3px; padding: 0.3em;}
#seclist {list-style-type: none;}
#seclist li {padding: 0.2em;}
img {display:none;}
</style>
</head>
<body>
<table id="myTable" class= "table table-bordered">
<tr>
<th class="col-md-6 text-center success">
List 1
</th>
<th class="col-md-6 text-center success">
List 2
</th>
</tr>
<tr>
<td class="col-md-6">
<ul id="firstlist">
<li>Apple <img src="next.jpg" id="next1"></li>
<li>Orange <img src="next.jpg" id="next2"></li>
<li>Avacado <img src="next.jpg" id="next3"></li>
<li>Banana <img src="next.jpg" id="next4"></li>
<li>Mango <img src="next.jpg" id="next5"></li>
<ul>
</td>
<td class="col-md-6">
<ul class = "seclist" id = "seclist"> </ul>
</td>
</tr>
</table>
<script>
$(function(){
$( "#firstlist" ).selectable();
});
$(function() {
$( "#seclist" ).selectable();
});
$("img").click(function() {
var text = $(this).closest("li").text();
$('<li />', {html: text}).appendTo('ul.seclist')
});
</script>
</body>
</html>
答案 0 :(得分:2)
检查以上链接。只需取消绑定点击事件
即可 $("img").click(function(event) {
var text = $(this).closest("li").text();
$('<li />', {html: text}).appendTo('ul.seclist');
$(this).unbind('click');
});
它不会删除该元素,只允许您第一次单击它。
答案 1 :(得分:1)
试试这个
$("img").on("click" , function() {
var text1 = $(this).closest("li").text();
$('ul.seclist').append("<li>"+text1+"</li>");
$(this).off("click");
});
或
$("img").on("click" , function() {
var text1 = $(this).closest("li").text();
$('<li />', {html: text1}).appendTo('ul.seclist');
$(this).off("click");
});