Javascript 从具有锚定和图像标记的输入更新列表的html
我想要一个jquery代码,请检查脚本中的注释。afetr单击此处我想要代码,以在li中添加inputText,其余不变 我不知道为什么第一次发布问题会让人毛骨悚然Javascript 从具有锚定和图像标记的输入更新列表的html,javascript,jquery,list,Javascript,Jquery,List,我想要一个jquery代码,请检查脚本中的注释。afetr单击此处我想要代码,以在li中添加inputText,其余不变 我不知道为什么第一次发布问题会让人毛骨悚然 <body> <div class="content"> <div class="main"> <input type="text" autofocus placeholder="Please write your ta
<body>
<div class="content">
<div class="main">
<input type="text" autofocus placeholder="Please write your task here....">
<button>Click To Add</button>
</div>
<div class="data">enter code here
<ul>
<li>Item aided shown here <a id="del-button" href="https://www.google.com">
<img src="del.png" alt="delete-button"> </a> </li>
</ul>
</div>
</ class="content">
<script>
$('document').ready(function () {
var cont = $('.content');
$('button').click(function () {
var inputText = $('input');
var newList = $('li').first().clone();
// now afetr click here i want code, to add inputText in li and rest the same
})
})
</script>
</body>
单击以添加
在这里输入代码
- 此处显示的项目
$('document').ready(函数(){
var cont=$('.content');
$(“按钮”)。单击(函数(){
变量inputText=$('input');
var newList=$('li').first().clone();
//现在,点击这里我想要代码,在li中添加inputText,其余都一样
})
})
试试这个:
$('button').click(function () {
var inputText = $('input').val();
var newList = $('<li></li>');
newList.append(inputText);
newList.append('<a id="del-button" href="https://www.google.com"><img src="del.png" alt="delete-button"> </a>');
$("ul").append(newList);
});
$(“按钮”)。单击(函数(){
var inputText=$('input').val();
var newList=$(“”);
newList.append(inputText);
newList.append(“”);
$(“ul”)。追加(新列表);
});
还要注意的是,HTML代码已被破坏,在
标记之前,您有
而不是
正在工作。请注意,我已经更新了代码,因为它有问题。它应该是$(“ul”).append(newList);而不是$(“li”)。追加(新列表);如果回答了您的问题,您可以接受此答案,因此您的问题将标记为已结束/已解决。正如你提到的,这是你的第一个问题,因此可能不知道这是如何工作的,为什么,只是检查一下