在我的程序中,有用于选择特定事件或所有事件的单选按钮。我的代码是
index.php:
<tr>
<td width="15%" align="left">View entry statistics<span class="mandetory_text">*</span></td>
<td width="2%" align="left" valign="middle">:</td>
<td width="1%"><input name="e_access" id="e_access_<?php echo $edit_row['id']; ?>" type="radio" value="yes" <?php if($edit_row['access_status']=='yes') {?> checked="checked" <?php }?> /></td>
<td width="11%">Permitted</td>
<td width="1%"><input name="e_access" id="e_access_<?php echo $edit_row['id']; ?>" type="radio" value="true" <?php if($edit_row['access_status']=='true') {?> checked="checked" <?php }?> /></td>
<td width="13%">Not permitted</td>
<td width="60%"></td>
</tr>
此代码用于创建和编辑事件。所以当我创建默认事件时,所有事件单选按钮都会被选中。对于特定的单选按钮,点击显示一个表格需要机会选择一些事件,直到这里,这很好,但当我编辑同一事件时,我想要的是,如果用所有事件创建单选按钮,则不需要显示表格,就像用特定事件创建一样(单选按钮)需要显示表格选择了哪些事件并打勾(选择)单选按钮。为此,我在脚本中编写了一个代码
<script>
$(document).ready(function() {
var selected = $("input[type='radio']:checked").val();
if(selected == 'all')
{
$(".edit_veri_table").hide();
}
});
</script>
但在编辑页面中,单选按钮(所有事件和特定事件)在页面加载时正确显示表格(如果已在特定事件按钮中选择)。
当特定按钮点击显示表格和所有事件按钮点击隐藏表格时,我该怎么做。。
当特定按钮点击显示表时
如果你只是想在特定的按钮上显示并在休息时隐藏,那么你可以尝试这样做:(演示包含一个静态数据集)
$(document).ready(function(){
$("button").on("click",function(){
if(this.id == "show"){
$(".table").show();
}else{
$(".table").hide();
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
</script>
<table class='table'>
<tr>
<td width="15%" align="left">View entry statistics<span class="mandetory_text">*</span></td>
<td width="2%" align="left" valign="middle">:</td>
<td width="1%"><input name="e_access" id="e_access_1" type="radio" value="yes" checked="checked" /></td>
<td width="11%">Permitted</td>
<td width="1%"><input name="e_access" id="e_access_2; ?>" type="radio" value="true" /></td>
<td width="13%">Not permitted</td>
<td width="60%"></td>
</tr>
</table>
<button id="show">SHOW</button> <button id="hide">HIDE!!</button> <button id="hide1">HIDE!</button>
注意:您应该始终在页面上显示unique id's
。因此:
<td width="1%"><input name="e_access" id="e_access_<?php echo $edit_row['id']; ?>" type="radio" value="yes" <?php if($edit_row['access_status']=='yes') {?> checked="checked" <?php }?> /></td>
<td width="1%"><input name="e_access" id="e_access_<?php echo $edit_row['id']; ?>" type="radio" value="true" <?php if($edit_row['access_status']=='true') {?> checked="checked" <?php }?> /></td>
是not valid
,因为它们都将具有same ids
。要么是use class
,要么确保为create unique
id。