Suppose there is 3 row,thus there is 3 different name of radio button and each of them have another 5 radio button with different value.
假设有3行,因此有3个不同的单选按钮名称,每个都有另外5个不同值的单选按钮。
Code:
$i = 1;
while ($row = mysql_fetch_assoc($result))
{
?>
<tr>
<td width="19"><?php echo $i ?></td>
<td colspan="4"> <?php echo $row["question"] ?></td>
<?php
echo '<td width="42"><Input type="Radio" id="1" Name="point' . $i . '" value="1" />1</td>';
echo '<td width="42"><Input type="Radio" id="2" Name="point' . $i . '" value="2" />2</td>';
echo '<td width="42"><Input type="Radio" id="3" Name="point' . $i . '" value="3" />3</td>';
echo '<td width="42"><Input type="Radio" id="4" Name="point' . $i . '" value="4" />4</td>';
echo '<td width="42"><Input type="Radio" id="5" Name="point' . $i . '" value="5" />5</td>';
?>
<br />
</tr>
<?php
$i++;}
2 个解决方案
#1
1
I'm thinking some like this:
我在想这样的事情:
$("button").click(function() {
var $rows = $("table tr");
var $checked = $rows.find("input:checked");
var remaining = $rows.length - $checked.length;
if(remaining > 0)
alert("answer all the questions: " + remaining + " remaining")
else
alert("sending info")
});
$(function() {
$("button").click(function() {
var $rows = $("table tr");
var $checked = $rows.find("input:checked");
var remaining = $rows.length - $checked.length;
if(remaining > 0)
alert("answer all the questions: " + remaining + " remaining")
else
alert("sending info")
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td width="19">1</td>
<td colspan="4"> question</td>
<td width="42"><Input type="Radio" id="1" Name="point1" value="1" />1</td>
<td width="42"><Input type="Radio" id="2" Name="point1" value="2" />2</td>
<td width="42"><Input type="Radio" id="3" Name="point1" value="3" />3</td>
<td width="42"><Input type="Radio" id="4" Name="point1" value="4" />4</td>
<td width="42"><Input type="Radio" id="5" Name="point1" value="5" />5</td>
<br />
</tr>
<tr>
<td width="19">2</td>
<td colspan="4"> question</td>
<td width="42"><Input type="Radio" id="1" Name="point2" value="1" />1</td>
<td width="42"><Input type="Radio" id="2" Name="point2" value="2" />2</td>
<td width="42"><Input type="Radio" id="3" Name="point2" value="3" />3</td>
<td width="42"><Input type="Radio" id="4" Name="point2" value="4" />4</td>
<td width="42"><Input type="Radio" id="5" Name="point2" value="5" />5</td>
<br />
</tr>
<tr>
<td width="19">3</td>
<td colspan="4"> question</td>
<td width="42"><Input type="Radio" id="1" Name="point3" value="1" />1</td>
<td width="42"><Input type="Radio" id="2" Name="point3" value="2" />2</td>
<td width="42"><Input type="Radio" id="3" Name="point3" value="3" />3</td>
<td width="42"><Input type="Radio" id="4" Name="point3" value="4" />4</td>
<td width="42"><Input type="Radio" id="5" Name="point3" value="5" />5</td>
<br />
</tr>
</table>
<button>submit</button>
#2
0
<script language="javascript">
$(function() {
$("button").click(function() {
var $rows = $("table tr");
var $checked = $rows.find("input:checked");
var remaining = $rows.length - $checked.length;
if(remaining > 0)
alert("answer all the questions: " + remaining + " remaining")
else
alert("sending info")
});
})
#1
1
I'm thinking some like this:
我在想这样的事情:
$("button").click(function() {
var $rows = $("table tr");
var $checked = $rows.find("input:checked");
var remaining = $rows.length - $checked.length;
if(remaining > 0)
alert("answer all the questions: " + remaining + " remaining")
else
alert("sending info")
});
$(function() {
$("button").click(function() {
var $rows = $("table tr");
var $checked = $rows.find("input:checked");
var remaining = $rows.length - $checked.length;
if(remaining > 0)
alert("answer all the questions: " + remaining + " remaining")
else
alert("sending info")
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td width="19">1</td>
<td colspan="4"> question</td>
<td width="42"><Input type="Radio" id="1" Name="point1" value="1" />1</td>
<td width="42"><Input type="Radio" id="2" Name="point1" value="2" />2</td>
<td width="42"><Input type="Radio" id="3" Name="point1" value="3" />3</td>
<td width="42"><Input type="Radio" id="4" Name="point1" value="4" />4</td>
<td width="42"><Input type="Radio" id="5" Name="point1" value="5" />5</td>
<br />
</tr>
<tr>
<td width="19">2</td>
<td colspan="4"> question</td>
<td width="42"><Input type="Radio" id="1" Name="point2" value="1" />1</td>
<td width="42"><Input type="Radio" id="2" Name="point2" value="2" />2</td>
<td width="42"><Input type="Radio" id="3" Name="point2" value="3" />3</td>
<td width="42"><Input type="Radio" id="4" Name="point2" value="4" />4</td>
<td width="42"><Input type="Radio" id="5" Name="point2" value="5" />5</td>
<br />
</tr>
<tr>
<td width="19">3</td>
<td colspan="4"> question</td>
<td width="42"><Input type="Radio" id="1" Name="point3" value="1" />1</td>
<td width="42"><Input type="Radio" id="2" Name="point3" value="2" />2</td>
<td width="42"><Input type="Radio" id="3" Name="point3" value="3" />3</td>
<td width="42"><Input type="Radio" id="4" Name="point3" value="4" />4</td>
<td width="42"><Input type="Radio" id="5" Name="point3" value="5" />5</td>
<br />
</tr>
</table>
<button>submit</button>
#2
0
<script language="javascript">
$(function() {
$("button").click(function() {
var $rows = $("table tr");
var $checked = $rows.find("input:checked");
var remaining = $rows.length - $checked.length;
if(remaining > 0)
alert("answer all the questions: " + remaining + " remaining")
else
alert("sending info")
});
})