JavaScript usage Tips

Source: Internet
Author: User
Tags contains net trim port number
Javascript| Tips

  (i). Confirm Deletion usage:

  1. BTNDEL.ATTRIBUTES.ADD ("onclick", "Return Confirm" ("+" confirm deletion?) +"')");
  2 linktempdelete.attributes["onclick"]= "javascript:return  confirm (' +" confirm deletion?) +"');";
  3. private void Grdproject_itemdatabound (object sender, DataGridItemEventArgs e)
  4.
  {
 if (E.item.itemtype = = ListItemType.Item) | (E.item.itemtype = = ListItemType.AlternatingItem))
 {
  //Delete the hint section on the button
  e.item.cells[10]. Attributes.Add ("onclick", "return Confirm" (' OK delete?) ');");
 }  
 }
  5.
    <script language= "JavaScript" type= "Text/javascript"
 function delete_y (e)
        {
    if (event.srcElement.outerText = "delete")
        event.returnvalue=confirm ("Confirm deletion");
 }
 document.onclick=delete_y;
    </script>

  (ii). Cross-language string substitution

System.Text.RegularExpressions.Regex.Replace (str1,@ "<{1}[^<>]*>{1}", ""). Replace ("", ""). Replace ("\", "\ \"). Replace ("-", "-"). Replace ("&", "&"). Replace ("<", "<"). Replace (">", ">"). Replace ("br", "\ n");

  (iii). Close form

1.
THIS.BTNCLOSE.ATTRIBUTES.ADD ("onclick", "window.close (); return false;");
2. Turn off this form to jump to another page
This. Hyperlink1.navigateurl = "Javascript:onclick=window.opener.location.assign
(' + "index.aspx" + "&func=edit&autoid=" + intautoid + '); Window.close (); ";
3. Close the parent form:
<input type= "reset" value= ' <%=this._Cancel%> ' class= "button" >


  (iv). Web MessageBox

1.
Response.Write ("<script language=javascript> Window.alert (' Save Success 1 ');</script>");
2.
Response.Write ("<script>alert" + "Save success!") + "');</script>");
3.
This. Page.registerstartupscript ("Chiname", "<script language= ' JavaScript ' >alert (' + ' save success!" + ") </script>") ;

  (v). Add a CheckBox control template column to the DataGrid.
Please see: http://blog.csdn.net/chengking/archive/2005/10/08/497520.aspx

  (vi). window.open () method

Grammar: window.open (pageurl,name,parameters);

The open () method of the Window object is used to create a new window instance, and the appearance of the newly created window is specified by the parameter: parameters. The document opened in the new window is made up of parameters:

Pageurl specified. The system can access the window based on its parameters: name-determined names.

The following table is the Parameters parameter table:
Parameter Panties Start Value description
Alwayslowered yes/no Specifies that the window is hidden beneath all windows.
Alwaysraised yes/no specifies that the window floats above all windows.
Dependent yes/no Specifies that the open window is a window of the parent window. and closes with the parent window closed.
Directions YES/NO Specifies whether Navigator 2 and 3 are visible in the new window.
Height pixel value sets the pixel height of the new window.
Hotkeys yes/no to set a secure exit hotkey in a new window without a menu bar.
Innerheight pixel value sets the pixel height of the document in the new window.
Innerwidth pixel value Sets the pixel width of the document in the new window.
Location yes/no Indicates whether the position bar is visible in the new window.
MenuBar yes/no Indicates whether the menu bar is visible in the new window.
The pixel height of the Outerheight Pixel Value setting window (including the trim border).
Outerwidth pixel value Sets the pixel width of the window (including the trim border).
Resizable yes/no Indicates whether the new window can be adjusted.
ScreenX pixel value sets the pixel length of the new window from the screen boundary.
ScreenY pixel value sets the pixel length of the new window from the edge of the screen.
ScrollBars yes/no Indicates whether the scroll bar is visible in the new window.
TitleBar yes/no Indicates whether the menu topic bar is visible in the new window.
Toolbar yes/no Indicates whether the toolbar is visible in the new window.
Width pixel value Sets the pixel widths of the window.
Z-look yes/no contains an array of each <pplet> label in the document.
Fullscreen yes/no whether the open form is displayed in full screen
Left pixel value sets the distance of the new window from the left side of the screen
Top pixel value sets the distance of the new window from above the screen

Example:
<title>window.open function </title>
<body>
<script language= "JavaScript" >
<!--
window.open ("", "name1", "width=100,height=200,toolbar=no,scrollbars=no,menubar=no,screenx=100,screeny=100");
-->
</script>
</body>

  (vii). Location objects

href entire URL string.
Protocol A string containing the first part of the URL, such as http:
The host contains a string with the host name: part of the port number in the URL. such as//www.cenpok.net/server/
Hostname A string containing the host name in the URL. such as Http://www.cenpok.net
Port contains a string of port numbers that may exist in the URL.
Pathname after the "/" in the URL. such as ~list/index.htm
The string after the hash "#" (the CGI parameter).
Search "?" String after the number (CGI parameter).

  (eight). Button capture

1.ctrl+enter Button Capture method
<body >
<script language= "JavaScript" >
<!--
function Dokeydown ()
{
if (event.ctrlkey && event.keycode = 13)
{
Alert ("You pressed the Ctrl + Enter")
}
}
-->
</script>
</body>
2.ALT Speed Czech key: Alt+a
<button accesskey=a title= "Alt+a" >Alt+A</button>
(ix). Control input, illegal characters cannot be entered into the TextBox.
<asp:textbox class= "Text"
Onkeypress= "if (Event.keycode < | | | Event.keycode >57) Event.returnvalue = false;"
Id= "Txty_revenue" style= "Text-align:right" runat= "Server" width= "90%" maxlength= ">"
</asp:textbox>
Note: This method controls the textbox only to receive the number: 0~9, also can define other input characters, such as: 65~123, only allow input: A~z and a~z.



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.