Common JavaScript code (7)

Source: Internet
Author: User

 

// 11

A script that implements the "edit" and "cancel" functions of the DataGrid to avoid page refresh.
<Script language = "JavaScript">
VaR selectrow = "";
VaR SelectObject;
Function editcell (thisobject, type)
{
VaR id = thisobject. ID;
VaR buttonid = "button" + type;
VaR ROW = ID. Replace (buttonid ,"");
If (type = 1 & selectrow. length> 0 & SelectObject! = NULL)
{
Editrow (selectrow, 2, SelectObject );
Selectrow = "";
}
If (type = 1) {selectrow = row; SelectObject = thisobject;} else {selectrow = ""; SelectObject = NULL ;}
Editrow (row, type, thisobject );
}
Function editrow (row, type, thisobject)
{
VaR visible1 = "NONE ";
VaR visible2 = "inline ";
If (type! = 1)
{
Visible1 = "inline ";
Visible2 = "NONE ";
}
VaR buttonid = "button" + type;
VaR style;
VaR I;
For (I = 1; I <8; I ++)
{
VaR name1 = row + "IMG" + I;
Document. All [name1]. getattribute ("style"). Display = visible1;
Name1 = row + "text" + I;
VaR name2 = row + "checkbox" + I;
Document. All [name2]. getattribute ("style"). Display = visible2;
If (type! = 1)
{
If (document. All [name1]. value = 1)
Document. All [name2]. Checked = true;
Else
Document. All [name2]. Checked = false;
}
}
VaR tdindex = thisobject. parentelement. cellindex;
If (type> 1) tdindex = tdindex-1;
Thisobject. parentelement. parentelement. cells [tdindex]. getattribute ("style"). Display = visible2;
Thisobject. parentelement. colspan = type;
VaR name;
Name = row + buttonid;
Document. All [name]. getattribute ("style"). Display = "NONE ";
If (type = 1)
{
Document. All [name]. parentelement. parentelement. getattribute ("style"). backgroundcolor = "lightyellow ";
Name = row + "button2 ";
Document. All [name]. getattribute ("style"). Display = "inline ";
}
Else
{
Document. All [name]. parentelement. parentelement. getattribute ("style"). backgroundcolor = "";
Name = row + "button1 ";
Document. All [name]. getattribute ("style"). Display = "inline ";
}
}
</SCRIPT>
<Asp: DataGrid id = "griditem" runat = "server" cellpadding = "0" borderstyle = "solid" autogeneratecolumns = "false"
Width = "100%" allowpaging = "true">
<Selecteditemstyle backcolor = "lightyellow"> </selecteditemstyle>
<Edititemstyle cssclass = "tdbg-dark" backcolor = "Ivory"> </edititemstyle>
<Itemstyle horizontalalign = "center" Height = "23px" cssclass = "tdbg"> </itemstyle>
<Headerstyle horizontalalign = "center" Height = "25px" cssclass = "Summary-title"> <Columns>
<Asp: boundcolumn datafield = "ID" readonly = "true" headertext = "Personnel ID">
<Headerstyle width = "120px"> </ASP: boundcolumn>
<Asp: boundcolumn readonly = "true" headertext = "name">
<Headerstyle width = "120px"> </ASP: boundcolumn>
<Asp: templatecolumn headertext = "">
<Headerstyle width = "60px"> <Itemtemplate>

<Input id = "checkbox1" style = "display: none" type = "checkbox" runat = "server">
<Input id = "text1" type = "text" runat = "server" style = "display: none">
</Itemtemplate>
</ASP: templatecolumn>
<Asp: templatecolumn headertext = "query permission">
<Headerstyle width = "60px"> <Itemtemplate>

<Input id = "checkbox2" style = "display: none" type = "checkbox" runat = "server" name = "checkbox2">
<Input id = "text2" type = "text" runat = "server" style = "display: none" name = "text2">
</Itemtemplate>
</ASP: templatecolumn>
<Asp: templatecolumn headertext = "entry permission">
<Headerstyle width = "60px"> <Itemtemplate>

<Input id = "checkbox3" style = "display: none" type = "checkbox" runat = "server" name = "checkbox3">
<Input id = "text3" type = "text" runat = "server" style = "display: none" name = "text3">
</Itemtemplate>
</ASP: templatecolumn>
<Asp: templatecolumn headertext = "Modify permission">
<Headerstyle width = "60px"> <Itemtemplate>

<Input id = "checkbox4" style = "display: none" type = "checkbox" runat = "server" name = "checkbox4">
<Input id = "text4" type = "text" runat = "server" style = "display: none" name = "text4">
</Itemtemplate>
</ASP: templatecolumn>
<Asp: templatecolumn headertext = "delete permission">
<Headerstyle width = "60px"> <Itemtemplate>

<Input id = "checkbox5" style = "display: none" type = "checkbox" runat = "server" name = "checkbox5">
<Input id = "text5" type = "text" runat = "server" style = "display: none" name = "text5">
</Itemtemplate>
</ASP: templatecolumn>
<Asp: templatecolumn headertext = "Export Permission">
<Headerstyle width = "60px"> <Itemtemplate>

<Input id = "checkbox6" style = "display: none" type = "checkbox" runat = "server" name = "checkbox6">
<Input id = "text6" type = "text" runat = "server" style = "display: none" name = "text6">
</Itemtemplate>
</ASP: templatecolumn>
<Asp: templatecolumn headertext = "Import Permission">
<Headerstyle width = "60px"> <Itemtemplate>

<Input id = "checkbox7" style = "display: none" type = "checkbox" runat = "server" name = "checkbox7">
<Input id = "text7" type = "text" runat = "server" style = "display: none" name = "text7">
</Itemtemplate>
</ASP: templatecolumn>
<Asp: buttoncolumn text = "save" headertext = "operation" commandname = "cmdsave">
<Itemstyle font-size = "10pt"> </itemstyle>
</ASP: buttoncolumn>
<Asp: templatecolumn>
<Itemtemplate>
<Input id = "button1" style = "cursor: hand; width: 35px; color: Blue; border-top-style: none; border-right-style: none; border-left-style: none; Background-color: transparent; text-Decoration: underline; border-bottom-style: none"
Onclick = "editcell (this, 1);" type = "button" value = "edit" runat = "server"> <input id = "button2" style = "cursor: hand; display: none; color: Blue; border-top-style: none; border-right-style: none; border-left-style: none; Background-color: transparent; text-Decoration: underline; border-bottom-style: none"
Onclick = "editcell (this, 2);" type = "button" value = "cancel" runat = "server">
</Itemtemplate>
</ASP: templatecolumn>
</Columns>
<Pagerstyle nextpagetext = "Next" prevpagetext = "previous"> </pagerstyle>
</ASP: DataGrid>

<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> dstree </title>
<Meta name = "author" content = "sTarsjz@hotmail.com">
<Style>
Body, TD {Font: 12px verdana}
# Treebox {background-color: # fffffa ;}
# Treebox. EC {margin: 0 5 0 5 ;}
# Treebox. hasitems {font-weight: bold; Height: 20px; padding: 3 6 0 6; margin: 2px; cursor: hand; color: #555555; Border: 1px solid # fffffa ;}
# Treebox. Items {Height: 20px; padding: 3 6 0 6; margin: 1px; cursor: hand; color: #555555; Border: 1px solid # fffffa ;}
</Style>
<Base href = "http://vip.5d.cn/star/dstree/"/>
<SCRIPT>
// Code by star 20003-4-7
VaR Hc = "color: #990000; Border: 1px solid # cccccc ";
VaR SC = "background-color: # efefef; Border: 1px solid # cccccc; color: #000000 ;";
VaR IO = NULL;
Function inittree (){
VaR rootn = document.all.menuxml.doc umentelement;
VaR SD = 0;
Document. onselectstart = function () {return false ;}
Document. All. treebox. appendchild (createtree (rootn, SD ));
}
Function createtree (thisn, SD ){
VaR nodeobj = Document. createelement ("span ");
VaR upobj = Document. createelement ("span ");
With (upobj ){
Style. marginleft = SD * 10;
Classname = thisn. haschildnodes ()? "Hasitems": "items ";
Innerhtml = "Onmousedown = function (){
If (event. Button! = 1) return;
If (this. getattribute ("cn ")){
This. setattribute ("open ",! This. getattribute ("open "));
This.cn. style. Display = This. getattribute ("open ")? "Inline": "NONE ";
This. All. Tags ("IMG") [0]. src = This. getattribute ("open ")? "Http://www.blueidea.com/img/common/logo.gif": "http://www.blueidea.com/img/common/logo.gif ";
}
If (IO ){
Io.runtimestyle.css text = "";
Io. setattribute ("selected", false );
}
IO = this;
This. setattribute ("selected", true );
This.runtimestyle.css text = SC;
}
Onmouseover = function (){
If (this. getattribute ("selected") return;
This.runtimestyle.css text = HC;
}
Onmouseout = function (){
If (this. getattribute ("selected") return;
This.runtimestyle.css text = "";
}
Oncontextmenu = contextmenuhandle;
Onclick = clickhandle;
}
If (thisn. getattribute ("treeid ")! = NULL ){
Upobj. setattribute ("treeid", thisn. getattribute ("treeid "));
}
If (thisn. getattribute ("href ")! = NULL ){
Upobj. setattribute ("href", thisn. getattribute ("href "));
}
If (thisn. getattribute ("target ")! = NULL ){
Upobj. setattribute ("target", thisn. getattribute ("target "));
}
Nodeobj. appendchild (upobj );
Nodeobj. insertadjacenthtml ("beforeend", "<br/> ")
If (thisn. haschildnodes ()){
VaR I;
VaR nodes = thisn. childnodes;
VaR Cn = Document. createelement ("span ");
Upobj. setattribute ("cn", CN );
If (thisn. getattribute ("open ")! = NULL ){
Upobj. setattribute ("open", (thisn. getattribute ("open") = "true "));
Upobj. getattribute ("cn"). style. Display = upobj. getattribute ("open ")? "Inline": "NONE ";
If (! Upobj. getattribute ("open") upobj. All. Tags ("IMG") [0]. src = "http://www.blueidea.com/img/common/logo.gif ";
}
For (I = 0; I <nodes. length; CN. appendchild (createtree (nodes [I ++], sd + 1 )));
Nodeobj. appendchild (CN );
}
Else {
Upobj. All. Tags ("IMG") [0]. src = "http://www.blueidea.com/img/common/logo.gif ";
}
Return nodeobj;
}
Window. onload = inittree;
</SCRIPT>
<SCRIPT>
Function clickhandle (){
// Your code here
}
Function contextmenuhandle (){
Event. returnvalue = false;
VaR treeid = This. getattribute ("treeid ");
// Your code here
}
</SCRIPT>
</Head>
<Body>
<XML id = menuxml>
<? XML version = "1.0" encoding = "gb2312"?>
<Dstreeroot text = "Root Node" open = "true" href = "http: //" treeid = "123">
<Dstree text = "Technical Forum" open = "false" treeid = "">
<Dstree text = "5 dmedia" open = "false" href = "http: //" target = "box" treeid = "12">
<Dstree text = "webpage code" href = "http: //" target = "box" treeid = "4353"/>
<Dstree text = "hand-drawn" href = "http: //" target = "box" treeid = "543543"/>
<Dstree text = "irrigation" href = "http: //" target = "box" treeid = "543543"/>
</Dstree>
<Dstree text = "blueidea" open = "false" href = "http: //" target = "box" treeid = "213">
<Dstree text = "Dreamweaver & amp; JS" href = "http: //" target = "box" treeid = "4353"/>
<Dstree text = "flashactionscript" href = "http: //" target = "box" treeid = "543543"/>
</Dstree>
<Dstree text = "csdn" open = "false" href = "http: //" target = "box" treeid = "432">
<Dstree text = "JS" href = "http: //" target = "box" treeid = "4353"/>
<Dstree text = "XML" href = "http: //" target = "box" treeid = "543543" type = "codeph" text = "codeph"/>
</Dstree>
</Dstree>
<Dstree text = "Resource Site" open = "false" treeid = "">
<Dstree text = "material Center" href = "http: //" target = "box" treeid = "12"/>
<Dstree text = "desktop City" open = "false" href = "http: //" target = "box" treeid = "213">
<Dstree text = "Wallpaper" href = "http: //" target = "box" treeid = "4353"/>
<Dstree text = "font" href = "http: //" target = "box" treeid = "543543"/>
</Dstree>
<Dstree text = "msdn" open = "false" href = "http: //" target = "box" treeid = "432">
<Dstree text = "DHTML" href = "http: //" target = "box" treeid = "4353"/>
<Dstree text = "HTC" href = "http: //" target = "box" treeid = "543543" type = "codeph" text = "codeph"/>
<Dstree text = "XML" href = "" target = "box" treeid = "2312"/>
</Dstree>
</Dstree>
</Dstreeroot>
</XML>
<Table Style = "position: absolute; left: 100; top: 100;">
<Tr> <TD id = treebox style = "width: 400px; Height: 200px; Border: 1px solid # cccccc; padding: 5 3 5 ;"
Valign = top> </TD> </tr>
<Tr> <TD style = "Font: 10px verdana; color: #999999" align = right>
<Font color = #660000> Star </font> <br/> </TD> </tr>
</Table>
</Body>
</Html>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.