gpt4 book ai didi

javascript - 从列表中选择后删除选定的复选框项目

转载 作者:行者123 更新时间:2023-12-02 15:06:59 24 4
gpt4 key购买 nike

我有一个弹出窗口,其中有一个可供选择的复选框项目列表。从弹出窗口中选择项目并单击“更新”按钮后,值将显示在页面上。

HTML 代码

<form action="" id="popup_form">

<div class="added">
<div class="column-left">
<label class="checkbox" for="checkbox1" style="font-size:20px;">
<input type="checkbox" name="complaint" value="One" id="checkbox1" data-toggle="checkbox">
One
</label>
<br/>
<label class="checkbox" for="checkbox2" style="font-size:20px;">
<input type="checkbox" name="complaint" value="Two" id="checkbox2" data-toggle="checkbox">
Two
</label>
<br/>

</div>

<div class="column-center">
<label class="checkbox" for="checkbox3" style="font-size:20px;">
<input type="checkbox" name="complaint" value="Three" id="checkbox3" data-toggle="checkbox">
Three
</label>
<br/>
<label class="checkbox" for="checkbox4" style="font-size:20px;">
<input type="checkbox" name="complaint" value="Four" id="checkbox4" data-toggle="checkbox">
Four
</label>
<br/>

</div>

<div class="column-center-right">
<label class="checkbox" for="checkbox5" style="font-size:20px;">
<input type="checkbox" name="complaint" value="Five" id="checkbox5" data-toggle="checkbox">
Five
</label>
<br/>
<label class="checkbox" for="checkbox6" style="font-size:20px;">
<input type="checkbox" name="complaint" value="Six" id="checkbox6" data-toggle="checkbox">
Six
</label>
<br/>

</div>

<div class="column-right">

<label class="checkbox" for="checkbox7" style="font-size:20px;">
<input type="checkbox" name="complaint" value=" Seven" id="checkbox7" data-toggle="checkbox">
Seven
</label>
<br/>
<label class="checkbox" for="checkbox8" style="font-size:20px;">
<input type="checkbox" name="complaint" value="Eight" id="checkbox8" data-toggle="checkbox">
Eight
</label>
<br/>

</div>

</div>
<br/>
<input type="submit" name="submit" id="update" class="button button-orange" style="width: 90px; margin-top: 450px;
margin-left: -533px;" value="Update">
<input type="submit" name="cancel" id="cancel" class="button button-orange" style="width: 90px; background-color:#36606e;" value="Cancel">

</form>

现在我希望所选项目应从弹出列表中删除。例如如果选择值“One”,则应从弹出列表项目中删除该项目并应显示在页面上。

我没有找到解决方案。我怎样才能用 jquery 或 javascript 得到它?

任何帮助都会有帮助。

弹出列表如下图所示enter image description here

点击“更新”后,所选项目将显示在页面上,如下所示 enter image description here

最佳答案

已更新

在另一个元素上查看所选项目

http://plnkr.co/edit/3lqVQfuqJ7ZTKMbIlGpH?p=preview

Jquery

$(document).ready(function() {

$('.push-button').click(function() {
$('input[name=complaint]:checked').parent().hide();
var list = $('.content ul');
list.empty();
$('input[name=complaint]:checked').each(function() {
var item = $('<li>');
item.html($(this).val());
list.append(item);
});

});
});

HTML

<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-2.1.4.js" data-semver="2.1.4" data-require="jquery"></script>
<script src="script.js"></script>
</head>

<body>
<div class="added">
<div class="column-left">
<label class="checkbox" for="checkbox1" style="font-size:20px;">
<input type="checkbox" name="complaint" value="One" id="checkbox1" data-toggle="checkbox">
One
</label>
<br/>
<label class="checkbox" for="checkbox2" style="font-size:20px;">
<input type="checkbox" name="complaint" value="Two" id="checkbox2" data-toggle="checkbox">
Two
</label>
<br/>

</div>

<div class="column-center">
<label class="checkbox" for="checkbox3" style="font-size:20px;">
<input type="checkbox" name="complaint" value="Three" id="checkbox3" data-toggle="checkbox">
Three
</label>
<br/>
<label class="checkbox" for="checkbox4" style="font-size:20px;">
<input type="checkbox" name="complaint" value="Four" id="checkbox4" data-toggle="checkbox">
Four
</label>
<br/>

</div>

<div class="column-center-right">
<label class="checkbox" for="checkbox5" style="font-size:20px;">
<input type="checkbox" name="complaint" value="Five" id="checkbox5" data-toggle="checkbox">
Five
</label>
<br/>
<label class="checkbox" for="checkbox6" style="font-size:20px;">
<input type="checkbox" name="complaint" value="Six" id="checkbox6" data-toggle="checkbox">
Six
</label>
<br/>

</div>

<div class="column-right">

<label class="checkbox" for="checkbox7" style="font-size:20px;">
<input type="checkbox" name="complaint" value=" Seven" id="checkbox7" data-toggle="checkbox">
Seven
</label>
<br/>
<label class="checkbox" for="checkbox8" style="font-size:20px;">
<input type="checkbox" name="complaint" value="Eight" id="checkbox8" data-toggle="checkbox">
Eight
</label>
<br/>

</div>

</div>

<button type="button" class="push-button">List Data To the Content </button>


<div class="content">
<h1>View Selected Datas</h1>
<ul class="content-list">

</ul>
</div>
</body>

</html>

关于javascript - 从列表中选择后删除选定的复选框项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35055412/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com