我想要的是如果我单击我的重置按钮,它会重置我的单选按钮并清除其可能的表格数据....我应该在这里添加什么代码......
function clear(){
var elems = document.getElementsByName('president') && document.getElementById('president');
for(i=0;i<elems.length;i++)
elems[i].checked=false;
document.list.editform.president.value='';
}
比如说document.getElementsByName('president')
用于我的编辑窗体上的重置按钮,document.getElementById('president')
用于我的表格数据,这是另一种形式。是否有可能如果我点击重置,我的功能会调用两个表格?帮助......
这是我的select_candidate.php
<script type="text/javascript">
<!--
function clear(){
var elems = document.getElementsByName('president');
for(i=0;i<elems.length;i++)
elems[i].checked=false;
document.list.editform.president.value='';
}
function get_president_value()
{
for (var i=0; i < document.list.president.length; i++)
{
if (document.list.president[i].checked)
{
return document.getElementById('president').innerHTML = document.list.president[i].value;
}
}
}
-->
</script>
<form method="post" name="list">
<div id="TabbedPanels1" class="TabbedPanels" >
<ul class="TabbedPanelsTabGroup">
<li class="TabbedPanelsTab" tabindex="0">President</li>
</ul>
<div class="TabbedPanelsContentGroup">
<div class="TabbedPanelsContent">
<fieldset>
<legend>President</legend>
<?php require_once('candidate/president.php'); ?>
</fieldset></div>
</form>
<!-- here the value of my radio button will appear on this table data and this is where i want to clear as i click my reset button which clears also my radio buttons... -->
<div>
<fieldset>
<legend>List of Your Candidates</legend>
<table>
<tr><td>President: </td> <td id="president" onclick="clear()"> </td> </tr>
</table>
</fieldset>
</div>
并且继承了我的总统.php
<?php
// get the records from the database
if ($result = $mysqli->query("SELECT * FROM candidate_info WHERE position= 'president'"))
{
// display records if there are records to display
if ($result->num_rows > 0)
{
// display records in a table
echo "<table border='1' cellpadding='10'>";
// set table headers
echo "<tr><th>Student ID</td><th>Course</th><th>Name</th></tr>";
while ($row = $result->fetch_object())
{
// set up a row for each record
echo "<tr>";
echo "<td>" . $row->studid . "</td>";
echo "<td>" . $row->course . "</td>";
echo "<td>" . $row->fname . " ". $row->mname ." ". $row->lname ." </td>";
echo "<td><input type ='radio' name='president' id='". $row->studid ."' value='" . $row->fname . " ". $row->mname ." ". $row->lname ."' onchange='get_president_value()' ></td>";
echo "</tr>";
}
echo "</table>";
}
// if there are no records in the database, display an alert message
else
{
echo "No results to display!";
}
}
// show an error if there is an issue with the database query
else
{
echo "Error: " . $mysqli->error;
}
// close database connection
$mysqli->close();
// <a href="records.php">Add New Record</a>
?>
//here is my reset button that resets my radio buttons
<form name="editform" method="post">
<input type="reset" name="reset" value="Clear" id="candidate2" onClick="clear()">
</form></div>
答案 0 :(得分:1)
Java Script Code use tableid.rows.length take number of row;
if(tabLen == 1){ return;}//its mean only header remaning no data
where rowId while creating table giving rowId string like "userRow" ;
for (i=1; i< tabLen; i++)
{
if (document.getElementById(rowId+(i-1)) != undefined)
tableToBeDeleted.deleteRow(document.getElementById(rowId+(i-1)).rowIndex);
else if (document.getElementById(rowId+"_New") != undefined)
tableToBeDeleted.deleteRow(document.getElementById(rowId+"_New").rowIndex);
}