当我点击悬停在文本上方时出现的图像时,该元素将被移动到另一个UL。我需要与第一个列表中相同的图像选项来删除它。我不知道如何动态添加它。 有人可以帮忙吗?提前致谢。
图片链接是:
https://www.signaturecontrolsystems.com/Support/SmallRedX.gif
<!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.4em;}
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" class = "list1"></li>
<li>Orange <img src="next.jpg" class = "list1"></li>
<li>Avacado <img src="next.jpg" class = "list1"></li>
<li>Banana <img src="next.jpg" class = "list1"></li>
<li>Mango <img src="next.jpg" class = "list1"></li>
<ul>
</td>
<td class="col-md-6">
<ul class = "seclist" id = "seclist"> </ul>
</td>
</tr>
</table>
<script>
$(function(){
$( "#firstlist" ).selectable();
});
$(function() {
$( "#seclist" ).selectable();
});
$(".list1").click(function() {
var text = $(this).closest("li").text();
$('<li />', {html: text}).appendTo('ul.seclist')
$(this).unbind('click');
});
</script>
</body>
</html>
答案 0 :(得分:1)
$(".list1").click(function() {
var text = $(this).closest("li").text();
$('<li/>', {html: text}).addClass("ui-selectee").appendTo('ul.seclist').append("<img src='cancel.jpg' class = 'list2 ui-selectee'/>");
this.style.visibility = 'hidden';
});
$('ul').on('click', '.list2', function(e) {
$(this).parent('li').remove();
var liTwo = $(this).closest("li").text();
var listItems = $("#firstlist li");
listItems.each(function(li) {
var liOne = $(this).text();
if(liTwo.match(liOne)){
document.getElementById(liOne.trim()).style.visibility = 'visible';
}
});
});
答案 1 :(得分:1)