<!DOCTYPE html>
<html lange="en"> <!-- 设置语音 -->
<head>
<meta charset="UFT-8"> <!-- 设置编码格式 -->
<title>Title</title>
</head>
<body>
<input id="t1" type="text"/>
<input id="t2" type="button" value="添加" />
<input id="t3" type="button" value="删除" />
<input id="t4" type="button" value="复制" />
<ul id="u1" >
<li>1</li>
<li>2</li>
</ul>
<script src="jquery-1.12.4.js"></script>
<script>
$('#t2').click(function (){
var v = $('#t1').val();
console.log(v);
var temp = '<li>' + v + '</li>' ;
$('#u1').append(temp);
// $('#u1').after(temp);
// $('#u1').before(temp);
// $('#u1').prepend(temp);
})
$('#t3').click(function () {
var index = $('#t1').val();
/*删除*/
$('#u1 li').eq(index).remove();
})
$('#t4').click(function (){
/*通过索引查找*/
var index = $('#t1').val();
console.log(index);
var v = $('#u1 li').eq(index).clone();
console.log(v);
$('#u1').append(v);
})
</script>
</body>
</html>
<html lange="en"> <!-- 设置语音 -->
<head>
<meta charset="UFT-8"> <!-- 设置编码格式 -->
<title>Title</title>
</head>
<body>
<input id="t1" type="text"/>
<input id="t2" type="button" value="添加" />
<input id="t3" type="button" value="删除" />
<input id="t4" type="button" value="复制" />
<ul id="u1" >
<li>1</li>
<li>2</li>
</ul>
<script src="jquery-1.12.4.js"></script>
<script>
$('#t2').click(function (){
var v = $('#t1').val();
console.log(v);
var temp = '<li>' + v + '</li>' ;
$('#u1').append(temp);
// $('#u1').after(temp);
// $('#u1').before(temp);
// $('#u1').prepend(temp);
})
$('#t3').click(function () {
var index = $('#t1').val();
/*删除*/
$('#u1 li').eq(index).remove();
})
$('#t4').click(function (){
/*通过索引查找*/
var index = $('#t1').val();
console.log(index);
var v = $('#u1 li').eq(index).clone();
console.log(v);
$('#u1').append(v);
})
</script>
</body>
</html>