有人请帮助我从复选框中获取ID并通过简单的jQuery代码将其放在href
项目上?
<a href="edit?id=dynamicText">Edit</a>
<a href="delete?id=dynamicText">Delet</a>
点击复选框后
<input type="checkbox" name="mycheck" id="1">
<input type="checkbox" name="mycheck" id="2">
<input type="checkbox" name="mycheck" id="3">
答案 0 :(得分:0)
以下是选中复选框时添加ID的示例。让我知道是否有帮助。
$(document).ready(function() {
$edit = $("#edit");
$checkedBoxes = [];
//for edit link only
$('input[type="checkbox"]').on('change', function(e) {
if (e.target.checked)
$checkedBoxes.push(e.target.id);
else
$checkedBoxes.pop(e.target.id);
$edit.attr('href', 'edit?id=' + $checkedBoxes.join('&'));
console.log('href: ', $edit.attr('href'));
})
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<a id="edit" href="edit?id=">Edit</a>
<a id="delete" href="delete?id=dynamicText">Delete</a>
<p>After I clicked the check-boxes</p>
<input type="checkbox" name="mycheck" id="1">
<input type="checkbox" name="mycheck" id="2">
<input type="checkbox" name="mycheck" id="3">