请帮助..我想要5个复选框的Javascript功能 [英] Please Help.. I Want Javascript Function For 5 Checkboxes
问题描述
亲爱的先生,
我有五个复选框。复选框放入表格列。喜欢
第一列第一个复选框,第二列第二列,第三列复选框。最后是第三列,第五个复选框。以下:
---------------------------------------- ------------------------------------------
第1栏|第2栏|第3栏
----------------------------------------- ---------------------------------------
Checkbox1 | Checkbox2 | Checkbox4
| checkbox3 |复选框5
--------------------------------- -------------------------------------------
当我选中复选框1,复选框3和复选框5保存复选框3时,复选框5值进入checkbox1和数据库表刷新页面取消选中所有复选框然后单击复选框后自动选中复选框(复选框3,复选框5)。
我的控制器代码:=
public ActionResult ModuleMapping()
{
WFID = Convert.ToInt32(Request [wfid]);
string mysql =select * from modules where parentid =+ WFID;
db.Query = mysql;
DataTable dt2 = db.GetTable();
ArrayList list = new ArrayList();
foreach(dt2.Rows中的DataRow dr)// dt- DataTable
{
list.Add(dr);
}
string itemString =< table width =' 100px' > < tr > ;
string itemString1 =;
Int32 ParentID = 0;
Int32 ParentValue = 0;
Int32 LevelID = 0;
Int32 Mcounter = 0;
Int32 LastValue = 0;
foreach(列表中的DataRow dr)
{
LevelID + = 1;
itemString1 + =< input 类型 =' hidden' id =' LastValue+ LevelID +' value = 0 > \ n;
itemString + =< td valign =' top' > < table width =' 200px' > ;
itemString + =< tr > ; < td > < b > + dr [Title] +< b > < td > < / tr > ;
mysql =选择Id,标题来自t+ dr [ID];
db.Query = mysql;
DataTable dt = db.GetTable();
ArrayList list2 = new ArrayList();
foreach(dt.Rows中的DataRow dr2)// dt- DataTable
{
list2.Add(dr2);
}
Mcounter = 0;
foreach(list2中的DataRow项目)
{
Mcounter + = 1;
string tt1 = item [ID]。ToString();
string tt2 = item [ID]。ToString();
string HidVar = Mcounter +$+ LevelID;
itemString + =< tr > ; < td > 跨度>;
itemString + =< input 类型 =' hidden' id =' Child $+ HidVar +' 值 =' + item [ID] +' > < /跨度>;
itemString + =< input type =' 复选框' 名称 = \ chkcountry \ id =' chk $+ HidVar +' value =' ' onclick =' javascript:clickme(\+ HidVar +\,+ tt1 + ,+ tt2 +,+ Mcounter +,+ LevelID +);' > < a href =' #' onclick =' javascript:clickme(\+ HidVar + \,+ tt1 +,+ tt2 +,+ Mcounter +,+ LevelID +);' > + item [Title] +< / a > 跨度>;
// itemString + =< 输入 type =' 复选框' id =' chk $+ ParentID +$+ itemMain.ID +$+ item.ID +$+ LevelID +' value =' ' > < a href =' #' onclick =' javascript:clickme(\+ HidVar +\,+ tt1 +,+ tt2 + ,+ LevelID +);' > + item.Title +< / a > ;
itemString + =< / td > < / tr > 跨度>;
}
ParentID = Convert.ToInt32(dr [ID]);
itemString + =< / td > < / table > 跨度>;
}
itemString + =< / tr > < /表格 > ;
ViewData [mystring] =(itemString + itemString1);
return View();
}
我的ModuleMapping.cshtml代码:=
@ {
ViewBag.Title =ModuleMapping;
布局=〜/ Views / Shared / MobileRozer.cshtml;
Int32 WorkFlowID = Convert.ToInt32(ViewData [data]);
}
< script type =text / javascriptsrc =http://code.jquery.com/jquery.min.js>< / script>
< ; script type =text / javascript>
var results = new Array();
函数clickme(HidVar,txt, txt1,Mcounter,LevelID,ignore,rb){
var ChildValue = document.getElementById(Child $+ HidVar).value;
var chk = document.getElementById(chk $+ HidVar).checked;
// alert(chk);
// var chk1 = document.getElementById(chk $+ HidVar).checked = true;
if(LevelID> 1 )
{
for(index = 1;指数< 4; ++ index){
if(Mcounter!= index&& document.getElementById(chk $+ HidVar).checked == false)
{
document.getElementById(chk $+ index +$+ LevelID).disabled = true;
}
if(document。 getElementById(chk $+ HidVar).checked == false)
{
document.getElementById(chk $+ index +$+ LevelID)。 disabled = false;
}
}
}
document.getElementById(LastValue+ LevelID).value = ChildValue;
var ParentValue = 0;
if(LevelID> 1){
ParentValue = document.getElementById(LastValue+( LevelID - 1))。value;
}
else {
ParentValue = document.getElementById(LastValue+(LevelID))。value;
}
//功能复选框(我,组){
//加载历史
// alert(Level ID:+ LevelID);
//删除状态 - 取消选中全部儿童的价值等级
var OneToOne = 1;
for(index = 0;指数< results.length; ++ index){
if(results [index] [2]> =(LevelID + 1)){
document.getElementById(chk $+ results [index] [4] +$+ results [index] [2])。checked = false;
//document.getElementById(\"chk$+ results [index] [4] +$+结果[index] [2])。disabled = true;
}
}
//一对一检查
var OneToNE = 0;
var ChildStatus = 0;
//设置状态 - 检查子级别的所有值
for(index = 0; index< results.length; ++ index){
if(结果) [index] [0] == ChildValue&& results [index] [2]> =(LevelID + 1)){
document.getElementById(chk $+ results [index] ] [4] +$+结果[index] [2])。checked = true;
if(OneToNE == 0){
//文件。的getElementById( chk $+结果[指数] [4] +$+结果[指数] [2])。禁用=假;
}
ChildStatus = 1 < br $>
}
}
//检查是否存在
var exists = 0;
for(index = 0;指数< results.length; ++ index){
if(results [index] [0] == ParentValue&& results [index] [1] == ChildValue&& results [index] [2] == LevelID&& results [index] [4] == Mcounter){
存在= 1;
if(chk == false&&& ChildStatus == 0){
removeByIndex(结果,索引);
}
else {
document.getElementById (chk $+结果[index] [4] +$+结果[index] [2])。checked = true;
}
}
}
//如果不存在则存储在数组中
if(exists == 0){
results.push([ParentValue,ChildValue,LevelID,HidVar,Mcounter, - ]);
}
document.getElementById(Button1)。click = results;
var fk = document.getElementById(Button1)。点击;
alert(fk);
}
function removeByIndex(arr,index){
arr.splice(index,1);
}
$(document).ready(function(){
$('#Button1')。click(function()
{
var favorite = [];
$ .each($(results),function()
{
favorite.push($(this).val());
});
alert(我最喜欢的运动是:+ favorite.join(,));
});
});
< / script>
< form name =addForm>
@ Html.Raw(ViewData [mystring]);
< input id =Button1type =buttonvalue =Save/>
< / form>
+ LevelID;
itemString + =< tr > < ; td > ;
itemString + =< 输入 type =' hidden' id =' Child
+ HidVar +' 值 =' + item [ID] + ' > ;
itemString + =< input type =' 复选框' 名称 = \ chkcountry \ id =' chk
+ HidVar + ' value =' ' onclick =' javascript:clickme(\+ HidVar +\,+ tt1 +,+ tt2 +,+ Mcounter +,+ LevelID +);' > < a href =' #' onclick =' javascript:clickme(\+ HidVar +\,+ tt1 +,+ tt2 +,+ Mcounter +,+ LevelID +);' > + item [Title] +< / a > ;
// itemString + =< 输入 type =' 复选框' id =' CHK
Dear sir ,
i have five checkboxes. Checkboxes place into table column. like
first column first checkbox, second column into second, third checkboxes row wise. and finally third column forth, fifth checkboxes. following:
----------------------------------------------------------------------------------
column 1 | Column 2 | column3
--------------------------------------------------------------------------------
Checkbox1 | Checkbox2 | Checkbox4
| checkbox3 | checkbox5
----------------------------------------------------------------------------
When i checked checkbox1 , checkbox3 and Checkbox5 save checkbox3 ,Checkbox5 value into checkbox1 and database table refresh page unchecked all checkboxes then after click checkbox1 automatically checked checkboxes(checkbox3 ,Checkbox5 ).
My Controller code:=
public ActionResult ModuleMapping()
{
WFID = Convert.ToInt32(Request["wfid"]);
string mysql = "select * from modules where parentid="+ WFID;
db.Query = mysql;
DataTable dt2 = db.GetTable();
ArrayList list = new ArrayList();
foreach (DataRow dr in dt2.Rows) // dt- DataTable
{
list.Add(dr);
}
string itemString = "<table width='100px'><tr>";
string itemString1 = "";
Int32 ParentID = 0;
Int32 ParentValue = 0;
Int32 LevelID = 0;
Int32 Mcounter = 0;
Int32 LastValue = 0;
foreach (DataRow dr in list)
{
LevelID += 1;
itemString1 += "<input type='hidden' id='LastValue" + LevelID + "' value=0>\n";
itemString += "<td valign='top'><table width='200px'>";
itemString += "<tr><td><b>" + dr["Title"] + "<b><td></tr>";
mysql = "select Id,title from t" + dr["ID"];
db.Query = mysql;
DataTable dt=db.GetTable();
ArrayList list2 = new ArrayList();
foreach (DataRow dr2 in dt.Rows) // dt- DataTable
{
list2.Add(dr2);
}
Mcounter = 0;
foreach (DataRow item in list2)
{
Mcounter += 1;
string tt1 = item["ID"].ToString();
string tt2 = item["ID"].ToString();
string HidVar = Mcounter + "$" + LevelID;
itemString += "<tr><td>";
itemString += "<input type='hidden' id='Child$" + HidVar + "' Value='" + item["ID"] + "'>";
itemString += "<input type='checkbox' name=\"chkcountry\" id='chk$" + HidVar + "' value='' onclick='javascript:clickme(\"" + HidVar + "\"," + tt1 + "," + tt2 + "," + Mcounter + "," + LevelID + ");'><a href='#' onclick='javascript:clickme(\"" + HidVar + "\"," + tt1 + "," + tt2 + "," + Mcounter + "," + LevelID + ");'>" + item["Title"] + "</a>";
//itemString += "<input type='checkbox' id='chk$" + ParentID + "$" + itemMain.ID + "$" + item.ID + "$" + LevelID + "' value=''><a href='#' onclick='javascript:clickme(\"" + HidVar + "\"," + tt1 + "," + tt2 + "," + LevelID + ");'>" + item.Title + "</a>";
itemString += "</td></tr>";
}
ParentID = Convert.ToInt32(dr["ID"]);
itemString += "</td></table>";
}
itemString += "</tr></table>";
ViewData["mystring"] = (itemString + itemString1);
return View();
}
My ModuleMapping.cshtml code:=
@{
ViewBag.Title = "ModuleMapping";
Layout = "~/Views/Shared/MobileRozer.cshtml";
Int32 WorkFlowID = Convert.ToInt32(ViewData["data"]);
}
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
var results = new Array();
function clickme(HidVar, txt, txt1, Mcounter, LevelID, ignore, rb) {
var ChildValue = document.getElementById("Child$" + HidVar).value;
var chk = document.getElementById("chk$" + HidVar).checked;
// alert(chk);
// var chk1 = document.getElementById("chk$" + HidVar).checked = true;
if (LevelID > 1)
{
for (index = 1; index < 4; ++index) {
if (Mcounter != index && document.getElementById("chk$" + HidVar).checked== false)
{
document.getElementById("chk$" + index + "$" + LevelID).disabled = true ;
}
if (document.getElementById("chk$" + HidVar).checked == false)
{
document.getElementById("chk$" + index + "$" + LevelID).disabled = false;
}
}
}
document.getElementById("LastValue" + LevelID).value = ChildValue;
var ParentValue = 0;
if (LevelID > 1) {
ParentValue = document.getElementById("LastValue" + (LevelID - 1)).value;
}
else {
ParentValue = document.getElementById("LastValue" + (LevelID)).value;
}
// function checkbox(me, group) {
//load History
//alert("Level ID: " + LevelID);
//Remove Status - Unchecked all the value for a child Level
var OneToOne = 1;
for (index = 0; index < results.length; ++index) {
if (results[index][2] >= (LevelID + 1)) {
document.getElementById("chk$" + results[index][4] + "$" + results[index][2]).checked = false;
//document.getElementById("chk$" + results[index][4] + "$" + results[index][2]).disabled = true;
}
}
//One to One Checking
var OneToNE = 0;
var ChildStatus = 0;
//Setting Status - checked all the value for a child Level
for (index = 0; index < results.length; ++index) {
if (results[index][0] == ChildValue && results[index][2] >= (LevelID + 1)) {
document.getElementById("chk$" + results[index][4] + "$" + results[index][2]).checked = true;
if (OneToNE == 0) {
//document.getElementById("chk$" + results[index][4] + "$" + results[index][2]).disabled = false;
}
ChildStatus = 1
}
}
//Checking if exist
var exist = 0;
for (index = 0; index < results.length; ++index) {
if (results[index][0] == ParentValue && results[index][1] == ChildValue && results[index][2] == LevelID && results[index][4] == Mcounter) {
exist = 1;
if (chk == false && ChildStatus == 0) {
removeByIndex(results, index);
}
else {
document.getElementById("chk$" + results[index][4] + "$" + results[index][2]).checked = true;
}
}
}
//IF not exist then storing in the array
if (exist == 0) {
results.push([ParentValue, ChildValue, LevelID, HidVar, Mcounter, "-"]);
}
document.getElementById("Button1").click = results;
var fk = document.getElementById("Button1").click;
alert(fk);
}
function removeByIndex(arr, index) {
arr.splice(index, 1);
}
$(document).ready(function () {
$('#Button1').click(function ()
{
var favorite = [];
$.each($(results), function ()
{
favorite.push($(this).val());
});
alert("My favourite sports are: " + favorite.join(", "));
});
});
</script>
<form name="addForm">
@Html.Raw(ViewData["mystring"]);
<input id="Button1" type="button" value="Save" />
</form>
" + LevelID; itemString += "<tr><td>"; itemString += "<input type='hidden' id='Child
" + HidVar + "' Value='" + item["ID"] + "'>"; itemString += "<input type='checkbox' name=\"chkcountry\" id='chk
" + HidVar + "' value='' onclick='javascript:clickme(\"" + HidVar + "\"," + tt1 + "," + tt2 + "," + Mcounter + "," + LevelID + ");'><a href='#' onclick='javascript:clickme(\"" + HidVar + "\"," + tt1 + "," + tt2 + "," + Mcounter + "," + LevelID + ");'>" + item["Title"] + "</a>"; //itemString += "<input type='checkbox' id='chk
这篇关于请帮助..我想要5个复选框的Javascript功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!