1
我为用户建立了一个小应用程序来请求构建机器。我通过在提交表单时将具体信息保存到localStorage中,然后遍历存储变量以显示请求的详细外观来实现此目的。此循环的显示部分通过本地存储循环,并附带ul
和li
输入与每台特定机器有关的每条信息。jQuery选择所有的孩子
下面是我的显示器在提交前看起来像什么的一个粗略示例。我需要选择每个input
的值,并在localStorage.Removeitem('all machine 1 input values go here');
内使用它,对于粗略的代码我很抱歉,我对这个大部分都是新的。
<ul name="machine-1">
<li><input type="button" value="Del"></li>
<li><input value="name1"></li>
<li><input value="number1"></li>
</ul>
<ul name="machine-2">
<li><input type="button" value="Del"></li>
<li><input value="name2"></li>
<li><input value="number2"></li>
</ul>
继承人我的循环部分建立列表。
$("#theRequest").append('<ul id="machine-'+ machinec +'"><li style="border:none;margin-left:0em;padding-right:0em;"><input class="delete" type="button" id="del-'
+ machinec +'" value="Del"></li><li>'
+ '</li><li style="border:none;margin-left:0em;padding-right:0em;"><input class="edit" type="hidden" value="Edit"></li>'
+ '</li><li><input style="width:35px;" disabled type="text" value="'
+ nomember + '"></li><li><input style="width:20px;" disabled type="text" value="'
+ ecmpny + '"></li><li><input style="width:20px;" disabled type="text" value="'
+ estore + '"></li><li><input style="width:60px;" disabled type="text" value="'
+ hmachineType + '"></li><li><input disabled type="text" value="'
+ efullname + '"></li><li><input disabled type="text" value="'
+ etitle + '"></li><li><input disabled type="hidden" value="'
+ hrequested + '"></li><li><input disabled type="hidden" value="'
+ eemail + '</li></ul>');
这是我如何'删除'特定的机器并将其清除localStorage。我基本上没有选择正确的,如果我是,我仍然认为它只会选择其中一个孙辈的价值观?
// Delete a Machine
$('.delete').click(function() {
if (confirm('Are you sure you want to remove this item?')) {
var parent = $(this).parents('ul');
var grandchildren = parent.children().children();
parent.hide();
inputName = grandchildren.attr('value');
localStorage.removeItem(inputName);
}
else {}
});
伟大的作品,非常感谢!每个作品都很完美。 –
没问题,很高兴帮助 – Klors