Some common problems on the web page and JavaScript solution code

Source: Internet
Author: User
Tags cdata

Only numbers and regular expressions can be entered.
<Input onkeyup = "value = value. Replace (// D +/g,'') ">

Only Chinese regular expressions can be entered.
<Input onkeyup = "value = value. Replace (/[-}]/g,'') ">

Automatically wrap an English string out of the table width
Word-wrap: Break-word; Word-break: Break-all;

Press enter to submit the form
<Body onload = "form.txt. Focus ()">
<Form name = "form">
<Input name = "TXT" size = "100" value = "Mouse: click I submit, and press enter to submit" onclick = "form. submit () "onkeydown =" If (event. keycode = 13) form. submit () ">
</Form>

Confirm deletion

<A href = 'javascript: If (confirm ("are you sure you want to delete it? ") Location =" boos. asp? & Areyou = Delete & page = 1 "'> Delete </a>

 

How to make the form feel free
<Input type = text style = "border: 1 solid #000000">
Or
<Input type = text style = "border-left: none; border-Right: none; border-top: none; border-bottom: 1 solid #000000"> </textarea>

How to remove the image link and click the dotted line around the image

<A href = "#" onfocus = "This. Blur ()"> </a>

Child Window refresh parent window

Window. opener. Location. Reload ()

 

Open a new window, and the width and height of the window are the actual height and width of the image.

 

Center the pop-up window
<SCRIPT>
Mywin = Window. Open ("about: blank", "", "width = 200, Height = 160 ");
Mywin. moveTo (screen. width/2-100, screen. Height/2-80 );
</SCRIPT>

Click a cell in the table to change the cell color.

<Script language = "JavaScript">
Function Test (t ){
For (VAR I = 0; I <t. Rows. length; I ++)
For (var j = 0; j <t. Rows [I]. cells. length; j ++)
T. Rows [I]. cells [J]. bgcolor = T. Rows [I]. cells [J] = event. srcelement? 'Red ':'';
}
</SCRIPT>
<Table width = "300" cellspacing = "1" bgcolor = "black" onclick = "test (this)">
<Tr bgcolor = "white" Height = "20"> <TD> </tr>
<Tr bgcolor = "white" Height = "20"> <TD> </tr>
<Tr bgcolor = "white" Height = "20"> <TD> </tr>
</Table>

Single answer questions

There are three single-region,
<Input type = radio name = 1> 222
<Input type = radio name = 2> 222
<Input type = radio name = 3> 222
How to select the first one before selecting one of the following two.

<SCRIPT>
Function Change (radobj ){
VaR OBJ = Document. getelementsbyname ("Radio2 ");
For (I = 0; I <obj. length; I ++ ){
OBJ [I]. Disabled =! Radobj. checked;
}
}
</SCRIPT>
<Input type = radio name = "radio1" onclick = change (this)> 222
<Input type = radio name = "Radio2" disabled> 222
<Input type = radio name = "Radio2" disabled> 222
 

Tbody area scroll bar

<HTML> <Meta http-equiv = Content-Type content = "text/html; charset = gb2312">
<Style type = text/CSS> body {
Font: 12px fine body; cursor: Default
}
TD {
Font: 12px fine body; cursor: Default
}
. Title {
Border-Right: #555 1px solid; padding-Right: 4px; border-top: # fff 1px solid; padding-left: 4px; Background: # CCC; padding-bottom: 4px; overflow: hidden; border-left: # fff 1px solid; cursor: hand; padding-top: 4px; border-bottom: #555 1px solid; white-space: nowrap
}
. CDATA {
Border-Right: # DDD 1px solid; padding-Right: 3px; border-top: # fff 1px solid; padding-left: 3px; Background: # FFF; padding-bottom: 3px; overflow: hidden; border-left: # fff 1px solid; padding-top: 3px; border-bottom: # DDD 1px solid; white-space: nowrap
}
</Style>

<Script language = JavaScript>
// Column Title (column name # column width # Data Alignment)
VaR datatitles = new array (
"Artist/group #90 # Left ",
"Album name #130 # Left ",
"Issuer #110 # Left ",
"Ranking #58 # center this week ",
"Ranking #58 # center ",
"Ranking #58 # center last week ",
"Weekly #58 # center ",
"Top ranking #58 # center ",
"Sales percentage #70 # Center ")

// Column data (two-dimensional array)
VaR datafields = new array ()
Datafields [0] = new array ("Xiao yaxuan", "love songs-kiss", "Viking Virgin", "1", "flat", "1 ", "2", "1", "2.9% ")
Datafields [1] = new array ("Zhang huimei", "Fever", "Warner", "2", "flat", "2", "2 ", "2", "2.1% ")
Datafields [2] = new array ("", "", "shock for all", "3", "flat", "3", "5 ", "1", "1.8% ")
Datafields [3] = new array ("s.h.e", "beautiful new world", "Hua Yan him", "4", "flat", "4", "6 ", "1", "1.2% ")
Datafields [4] = new array ("avier", "Zhan Fei", "boundun BMG", "5", "", "-", "1 ", "5", "1.1% ")
Datafields [5] = new array ("", "", "Rolling Rock", "6", "", "-", "1 ", "6", "1.0% ")
Datafields [6] = new array ("fan yichen", "fan yichen's first album", "Feng Hua forward", "7", "flat", "7", "2 ", "7", "0.9% ")
Datafields [7] = new array ("Xie Yunfeng", "invisible his full selection", "Xinli Sony", "8", "down", "6 ", ("4", "4", "0.9% ")
Datafields [8] = new array ("", "lonely city", "fumao Decca", "9", "down", "5", "3 ", "5", "0.8% ")
Datafields [9] = new array ("Jay Chou", "", "Boulder BMG", "10", "", "8", "8 ", "1", "0.8% ")
Datafields [10] = new array ("Cool play orchestra", "overhead", "coyi hundred generations EMI", "11", "Rising", "16", "2 ", "11", "0.7% ")
Datafields [11] = new array ("Zhang zhenyue", "Wait for me one day", "magicstone", "12", "new rankings", "-", "1 ", "12", "0.6% ")
Datafields [12] = new array ("" "," Red and Blue "," avex "," 13 "," ","-"," 1 ", "13", "0.6% ")
Datafields [13] = new array ("energy", "come on", "universuniversal", "14", "down", "10", "9 ", "5", "0.6% ")
Datafields [14] = new array ("Edison Chen", "transition", "Echo avex", "15", "fall", "9", "3 ", "5", "0.4% ")
Datafields [15] = new array ("", "MTV hip hop master", "universuniversuniversal", "16", "", "12", "3 ", "12", "0.4% ")

</SCRIPT>

<Script language = JavaScript>
VaR boxwidth = 480 // display width of the data table (excluding scroll)
VaR showline = 10 // Number of columns displayed in the data table
VaR rsheight = 21 // data column height
VaR lockcols = 1 // Number of columns to be locked (from left to right)

Function writetable () {// write table
VaR iboxwidth = boxwidth
VaR newhtml = "<Table border =/" 0/"cellpadding =/" 0/"cellspacing =/" 0/"> <tr>/
<TD> <Div style =/"width: 100%; overflow-X: Scroll/">/
<Table border =/"0/" cellpadding =/"0/" cellspacing =/"0/"> <tr>"
For (I = 0; I <datatitles. length; I ++ ){
If (I <lockcols ){
VaR ctitle = datatitles [I]. Split ("#")
Iboxwidth-= ctitle [1]
VaR dyntip = (I + 1) = lockcols )? "Unlock": "lock this column"
Newhtml + = "<TD> <Div class =/" title/"style =/" width: "+ ctitle [1] +" PX; height: "+ rsheight +" PX/"Title =/" "+ dyntip +"/"onclick =/" resettable ("+ I + ") /">" + ctitle [0] + "</div> </TD>"
}
}
Newhtml + = "</tr>/
<Tr> <TD colspan =/"" + lockcols + "/">/
<Div id =/"dataframe1/" style =/"position: relative; width: 100%; overflow: hidden/">/
<Div id =/"datagroup1/" style =/"position: relative/"> </div>/
</TD> </tr> </table> </div> </TD>/
<TD valign =/"Top/"> <Div style =/"width:" + iboxwidth + "PX; overflow-X: Scroll/">/
<Table border =/"0/" cellpadding =/"0/" cellspacing =/"0/"> <tr>"
For (I = 0; I <datatitles. length; I ++ ){
If (I> = lockcols ){
VaR ctitle = datatitles [I]. Split ("#")
Newhtml + = "<TD> <Div class =/" title/"style =/" width: "+ ctitle [1] +" PX; height: "+ rsheight +" PX/"Title =/" lock this column/"onclick =/" resettable ("+ I + ") /">" + ctitle [0] + "</div> </TD>"
}
}
Newhtml + = "</tr>/
<Tr> <TD colspan =/"" + (datatitles. Length-lockcols) + "/">/
<Div id =/"dataframe2/" style =/"position: relative; width: 100%; overflow: hidden/">/
<Div id =/"Your roup2/" style =/"position: relative/"> </div>/
</Div> </TD> </tr> </table>/
</Div> </TD> <TD valign =/"Top/">/
<Div id =/"dataframe3/" style =/"position: relative; Background: #000; overflow-Y: Scroll/" onscroll =/"sync_roll ()/">/
<Div id =/"Your roup3/" style =/"position: relative; width: 1px; visibility: hidden/"> </div>/
</Div> </TD> </tr> </table>"
Datatable. innerhtml = newhtml
Applydata ()
}

Function applydata () {// write data
VaR newhtml = "<Table border =/" 0/"cellpadding =/" 0/"cellspacing =/" 0/">"
For (I = 0; I <datafields. length; I ++ ){
Newhtml + = "<tr>"
For (j = 0; j <datatitles. length; j ++ ){
If (j <lockcols ){
VaR ctitle = datatitles [J]. Split ("#")
Newhtml + = "<TD> <Div class =/" CDATA/"style =/" width: "+ ctitle [1] +" PX; height: "+ rsheight +" PX; text-align: "+ ctitle [2] +"/">" + datafields [I] [J] + "</div> </TD>"
}
}
Newhtml + = "</tr>"
}
Newhtml + = "</table>"
Export roup1.innerhtml = newhtml

VaR newhtml = "<Table border =/" 0/"cellpadding =/" 0/"cellspacing =/" 0/">"
For (I = 0; I <datafields. length; I ++ ){
Newhtml + = "<tr>"
For (j = 0; j <datatitles. length; j ++ ){
If (j> = lockcols ){
VaR ctitle = datatitles [J]. Split ("#")
Newhtml + = "<TD> <Div class =/" CDATA/"style =/" width: "+ ctitle [1] +" PX; height: "+ rsheight +" PX; text-align: "+ ctitle [2] +"/">" + datafields [I] [J] + "</div> </TD>"
}
}
Newhtml + = "</tr>"
}
Newhtml + = "</table>"
Export roup2.innerhtml = newhtml
Dataframe1.style. pixelheight = rsheight * showline
Dataframe2.style. pixelheight = rsheight * showline
Dataframe3.style. pixelheight = rsheight * showline + rsheight
Repeated roup3.style. pixelheight = rsheight * (datafields. Length + 1)
}

Function resettable (n ){
VaR iboxwidth = 0
For (I = 0; I <datatitles. length; I ++ ){
If (I <(n + 1 )){
VaR ctitle = datatitles [I]. Split ("#")
Iboxwidth + = parseint (ctitle [1])
}
}
If (iboxwidth> boxwidth ){
VaR sure = confirm ("/n the width of the lock column is greater than the width/n degrees displayed in the data table, which may cause the layout to be abnormal. /N are you sure you want to continue? ")
} Else {
Sure = true
}
If (SURE ){
Lockcols = (lockcols = n + 1 )? 0: n + 1
Writetable ()
}
}

Function sync_roll (){
Repeated roup1.style. postop =-dataframe3.scrolltop
Repeated roup2.style. postop =-dataframe3.scrolltop
}
Window. onload = writetable
</SCRIPT>

<Meta content = "mshtml 6.00.2800.1170" name = generator> <Body>
<Center>
<H4> lock the table column sample webpage </H4> <! -- // Data table (start) // -->
<Table cellspacing = 0 cellpadding = 0 border = 0>
<Tbody>
<Tr>
<TD
Style = "border-Right: White 2px inset; border-top: White 2px inset; border-left: White 2px inset; border-bottom: White 2px inset; Background-color: scrollbar ">
<Div id = datatable> </div> </TD> </tr> </tbody> </table> <! -- // Data table (end) // -->
<P> click the title of the column to reset or unlock the current lock status </P> </center> </body>

 

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.