I am trying to change the name to null/empty of all checkboxes which is unchecked on onchange
event and on ondocumentready
event using jquery.
(我试图将所有复选框的名称更改为null / empty,这在使用ondocumentready
onchange
事件和ondocumentready
事件中未选中。)
this is my code
(这是我的代码)
<div id="tab_4">
<div class="col-xs-12">
<input type="text" name="txtbox1" value="1">
<input type="checkbox" name="chkbox1" value="1">
<input checked type="checkbox" name="chkbox2" value="2">
<input type="checkbox" name="chkbox3" value="3">
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#tab_4 input[type=checkbox]').each(function(i){
if($(i).not(':checked'))
{
$(this).attr('name', '');
}
});
});
$('#tab_4 input[type=checkbox]').change(function(){
$('#tab_4 input[type=checkbox]').each(function(i){
if($(i).not(':checked'))
{
$(this).attr('name', '');
}
});
});
</script>
But it makes all name attribute to null even checked ones .
(但这会使所有name属性都变为null, 即使选中的也是如此 。)
I used this answer Changing input name using JQUERY
(我用这个答案使用JQUERY更改输入名称)
ask by Danial212k translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…