复选框列表的Javascript [英] Javascript for check box list

查看:66
本文介绍了复选框列表的Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的aspx页面上有四个复选框列表.
场景是每个复选框列表都有不同值的复选框.
我希望当任何用户单击这些复选框时,如果所有选中的复选框的值之和超过1,则显示总和超过1

我正在使用以下javascript函数

I have four check box list on my aspx page.
The scenario is that each check box list have check boxes with different-different value.
I want that when any user click on those check boxes then sum of value of all selected checkboxes if crosses 1 then it shows a message like that it exceeds 1

i am using the following javascript function

<script type="text/javascript" language="javascript">
        //-------------------function hardcode to perform on checklist box--------
        var total = 0;
        var histvalue = 0;
        var valueOfbx = 0;
        var currvalue = 0;
        function MutExChkList(chk) {
            if (chk.checked) {
                valueOfbx = 0;
                var chklst = chk.parentNode.parentNode.parentNode;
                var chkbx = chklst.getElementsByTagName("input");
                for (var i = 0; i < chkbx.length; i++) {
                    if ((chkbx[i].checked == true) && (chkbx[i].value != chk.value)) {
                        valueOfbx = Number(chkbx[i].value);
                        histvalue = -1;
                        chkbx[i].checked = false;
                    }
                    else if ((chkbx[i].checked == true) && (chkbx[i].value == chk.value)) {
                        currvalue = Number(chkbx[i].value);
                    }
                }
                total = total + currvalue;
                if (histvalue == -1) {
                    total = total - valueOfbx;
                    histvalue = 0;
                }
                if (total > 1) {
                    total = total - Number(chk.value);
                    chk.checked = false;
                    alert("exceeds");
                }
                else
                    chkbx[i].checked = false;
            }
            else {
                total = total - Number(chk.value);
            }
        }

    </script>



它在我的系统上完美运行,但是当我尝试在其他系统上运行时,它没有复选框的价值
请帮帮我


在此先感谢



it works perfectly on my system but as i tried to work this on other systems then it does not value of checkboxes
Please help me


Thanks in advance

推荐答案

var chklst = chk.parentNode.parentNode.parentNode;



也许这就是将代码传输到另一个HTML页面时出现问题的原因. 尝试检查控件的层次结构是否仍然相同.



Maybe that''s what makes the problem when transferring the code to another HTML page.
Try to check the hierarchy of controls if it still the same.


这篇关于复选框列表的Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆