如图所示: 这个用table写的 checkbox放在<td>标签里,我之前写的那个是table里全部的复选框,多选了会提示只能选几个。代码是这样的:<script type="text/javascript">
function setCheckValue() {
var obj = document.getElementById("MainContent_hdTimesCheckValue");
var cheked_num=0; //准备选择的checkbox
var hadcheked_num=0; //已经选择的checkbox
var count_num = <%=lg.ToInt(practiceCountTimes)%>;
if (obj != undefined && obj != null) {
var chk = document.getElementsByName("chkPracticeTimes");
if (chk != undefined && chk != null) {
obj.value = "";
if (chk.length == undefined) {
if (chk.checked) obj.value = chk.valueOf;
} else {
for (var i = 0; i < chk.length; i++) {
if (chk[i].checked) {
cheked_num+=1;
if (count_num!=0&&cheked_num>count_num) {
alert("最多只能选"+count_num+"个!");
event.srcElement.checked = false;
// cheked_num--;
i--;
}
obj.value += "|" + chk[i].value;
}
} }
}
} }</script>
现在是想要根据日期限制每行复选框的的选项,就是table里每行的复选框都限制不一样的,选多了会提示只能选多少个的那种。已经折腾几天了,有哪位js高手帮帮忙吧 ,在痛苦中!!我现在只有这么多分了,因为比较急,所以没去换分呢,希望帮帮忙吧,谢谢啦!!JavaScriptCheckBoxtable
function setCheckValue() {
var obj = document.getElementById("MainContent_hdTimesCheckValue");
var cheked_num=0; //准备选择的checkbox
var hadcheked_num=0; //已经选择的checkbox
var count_num = <%=lg.ToInt(practiceCountTimes)%>;
if (obj != undefined && obj != null) {
var chk = document.getElementsByName("chkPracticeTimes");
if (chk != undefined && chk != null) {
obj.value = "";
if (chk.length == undefined) {
if (chk.checked) obj.value = chk.valueOf;
} else {
for (var i = 0; i < chk.length; i++) {
if (chk[i].checked) {
cheked_num+=1;
if (count_num!=0&&cheked_num>count_num) {
alert("最多只能选"+count_num+"个!");
event.srcElement.checked = false;
// cheked_num--;
i--;
}
obj.value += "|" + chk[i].value;
}
} }
}
} }</script>
现在是想要根据日期限制每行复选框的的选项,就是table里每行的复选框都限制不一样的,选多了会提示只能选多少个的那种。已经折腾几天了,有哪位js高手帮帮忙吧 ,在痛苦中!!我现在只有这么多分了,因为比较急,所以没去换分呢,希望帮帮忙吧,谢谢啦!!JavaScriptCheckBoxtable
解决方案 »
- Opera浏览器代码调试工具有吗?就像chrome和IE那种按F12察看的。
- ajax调用在jquery-1.4.2.js不能运行,而jquery-1.3.2.min.js则可以
- 请教这里的JSer们,怎么修改网页内的字串?
- Comet应用时遇到问题,请大家帮忙看看怎么回事?
- js脚本引起的无法访问internet 站点的问题
- 请教怎样在frame中打开文件
- 求ajax和xml的书
- body的onoad和css,在外部则不起作用?
- 如何在html里显示另一文件的的内容?
- 求助!如何动态显示中文日期?
- 我想用split来截取字符串,如果多行时候同时进行截取转换
- IE10 FCK Editor 不支持selectSingleNode 如何解决?
然后点击一行的复选框的时候 取出日期td的那个属性比较下就ok了
我就是在日期那里放了一个隐藏的值,这个值就是限制每行的个数的<td class='tdDate'>2013-6-10 <input type='hidden' name='hPriceDateTime' id='hPriceDateTime' value='1'></td> 然后 复选框是这样的<td class='tdDate'>2013-6-10 <input type='hidden' name='hPriceDateTime' id='hPriceDateTime' value='1'></td>
<td class='tdDisable'><input type='checkbox' name='chkPracticeTimes' id='chkPracticeTimes' value='2013-06-10 08:00' onclick='setCheckValue()' disabled ></td> 我是想要遍历这个table 然后根据每行所选的复选框值得总数来比较,可是我遇到瓶颈了,就是不知道怎么从 table的<td>里获取input控件的值,和这一行里再遍历一下checkbox。
var getTr01=document.getElementById("tr1");
var getTr01Input=getTr01.getElementsByTagName("input");然后再便利他的checked属性值,获取个数和tr里隐藏的个数比较。不知道我又没有把你的需求理解错
<head>
<meta charset="UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js" type="text/javascript"></script>
<script>
$(function(){
$("table.table1 input[type='checkbox']").click(function(){
var tr=$(this).closest("tr");
var maxcheckedLen=~~(tr.attr("maxChecked"));
var checkedLen=$("input[type='checkbox']:checked",tr).length;
if(maxcheckedLen<checkedLen){
alert("超过最大限制!");
$(this).prop("checked",false);
}
});
});
</script>
</head>
<body><table width="977" border="1" class="table1">
<tr maxChecked="2">
<td><input type="checkbox" ></td>
<td><input type="checkbox" ></td>
<td><input type="checkbox" ></td>
<td><input type="checkbox" ></td>
<td><input type="checkbox" ></td>
</tr>
<tr maxChecked="3">
<td><input type="checkbox" ></td>
<td><input type="checkbox" ></td>
<td><input type="checkbox" ></td>
<td><input type="checkbox" ></td>
<td><input type="checkbox" ></td>
</tr>
</table></body>
</html>不知道我有没有把你的需求理解错
<head>
<meta charset="UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js" type="text/javascript"></script>
<script>
$(function(){
$("table.table1 input[type='checkbox']").click(function(){
var tr=$(this).closest("tr");
var maxcheckedLen=~~(tr.attr("maxChecked"));
var checkedLen=$("input[type='checkbox']:checked",tr).length;
if(maxcheckedLen<checkedLen){
alert("超过最大限制!");
$(this).prop("checked",false);
}
});
});
function getValue(){
var values=[];
$("input[type='checkbox']:checked").each(function(){
values.push($(this).val());
});
alert(values.join('|'));
}
</script>
</head>
<body>
<input width="80px" type="button" onclick="getValue();" value='GetValue' />
<table width="977" border="1" class="table1">
<tr maxChecked="2">
<td><input type="checkbox" value=31 ></td>
<td><input type="checkbox" value=21></td>
<td><input type="checkbox" value=15></td>
<td><input type="checkbox" value=18></td>
<td><input type="checkbox" value=17></td>
</tr>
<tr maxChecked="3">
<td><input type="checkbox" value=14></td>
<td><input type="checkbox" value=13></td>
<td><input type="checkbox" value=12></td>
<td><input type="checkbox" value=11></td>
<td><input type="checkbox" value=10></td>
</tr>
</table>
</body>
</html>加了个取值的方法
我那个修改内容的时候,这个取值和限制的效果都没问题了,现在就是添加内容的时候那个限制选项的效果就是没有,我那个表格是当满足一定的条件才可以选择,就是有点绑定触发事件的那种,而添加时一开始默认不可选,像这样 然后点击某个按钮,才可以选择,但是这样的话,你写的那个jquery效果不起作用。
不知道你明白我说的情况没有
一个项目里的代码 是mvc的 相互调用的,我不知道怎么贴啊