想利用Javascript实现以下功能:
1.所有文本框只能输入数字
2.“题目个数”一列至少要有一个文本框填写数字
3.如果“单选题”、“多选题”、“填空题”、“简答题”、“操作题”的任意行中的“题目个数”填写了,与之对应的“分值”必须填写,“1级难度”……“5级难度”中至少有一个文本框中有数字。描述的有些拗口,有不明白的告诉,谢谢
1.所有文本框只能输入数字
2.“题目个数”一列至少要有一个文本框填写数字
3.如果“单选题”、“多选题”、“填空题”、“简答题”、“操作题”的任意行中的“题目个数”填写了,与之对应的“分值”必须填写,“1级难度”……“5级难度”中至少有一个文本框中有数字。描述的有些拗口,有不明白的告诉,谢谢
<table id="table1">
<tr>
<th></th>
<th>题目个数</th>
<th>分值</th>
<th>1级难度</th>
<th>2级难度</th>
<th>3级难度</th>
<th>4级难度</th>
<th>5级难度</th>
</tr>
<tr>
<th>单项选择题:</th>
<td><input class="subject" /></td>
<td><input class="score" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
</tr>
<tr>
<th>多项选择题:</th>
<td><input class="subject" /></td>
<td><input class="score" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
</tr>
<tr>
<th>填空题:</th>
<td><input class="subject" /></td>
<td><input class="score" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
</tr>
<tr>
<th>简答题:</th>
<td><input class="subject" /></td>
<td><input class="score" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
</tr>
<tr>
<th>操作题:</th>
<td><input class="subject" /></td>
<td><input class="score" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
<td><input class="degree" /></td>
</tr>
</table>
<button id="button1" type="button">检查</button> $('#button1').bind('click', function() {
$('#table1 .subject').each(function() {
if ($(this).val() != '') {
var parent = $(this).parents('tr'), isEmpty = true, error = false;
if (isNaN($(this).val())) {
alert('只能输入数字!');
return false;
}
if (parent.find('.score').val() == '') {
alert(parent.find('th').text() + ' 对应的分值没有填写!');
return false;
}
else {
if (isNaN(parent.find('.score').val())) {
alert('只能输入数字!');
return false;
}
}
parent.find('.degree').each(function() {
if ($(this).val() != '') {
isEmpty = false;
if (isNaN($(this).val())) {
alert('只能输入数字!');
error = true;
return false;
}
}
});
if (error) return false;
if (isEmpty) {
alert(parent.find('th').text() + ' 难度没有填写!');
return false;
}
}
});
});