Some minor issues encountered when writing js

Source: Internet
Author: User

1. Write <asp: Button……> In the OnClientClick event, add return; otherwise, OnClientClick returns false, but The OnClick event is still executed.
For example:
Copy codeThe Code is as follows:
<Asp: Button ID = "btnSearch" runat = "server" CssClass = "button" Text = "find .... "OnClientClick =" return CheckBox (); "OnClick =" btnSearch_Click "> </asp: Button>

2. open a new window in window. showModalDialog () mode. if it contains a js editor or another third-party editor, the editor cannot be edited;
So far, I have not found a better solution. I should try it in the window. open () mode.
3. All checkbox selections:
Html:
Copy codeThe Code is as follows:
<Input type = "checkbox" id = "chkAll" onclick = "selectAll ()"/> select all
<Asp: CheckBoxList ID = "ckblist" runat = "server" RepeatLayout = "Flow" RepeatDirection = "Horizontal"> </asp: CheckBoxList>

Js:
Copy codeThe Code is as follows:
Function selectAll ()
{
Var obj = document. getElementById ("chkAll ");
Var ckblist = document. getElementById ("ckblist ");
Var chk = ckblist. getElementsByTagName ("input ");
If (obj. checked)
{
For (var I = 0; I <chk. length; I ++)
{
Chk [I]. checked = true;
}
}
Else
{
For (var I = 0; I <chk. length; I ++)
{
Chk [I]. checked = false;
}
}
}

Below are some basic js knowledge
Copy codeThe Code is as follows:

// Js retrieves the Table and changes its style
<Script type = "text/javascript">
Function setColSpan ()
{
Var x = document. getElementById ('mytable'). rows [0]. cells // obtain the first row of the table
X [0]. colSpan = "1" // change the table style.
X [1]. colSpan = "3" // same as above
}
</Script>
<Table id = "myTable" border = "1">
<Tr>
<Td colspan = "2"> cell 1 </td>
<Td colspan = "2"> Cell 2 </td>
</Tr>
<Tr>
<Td> cell 3 </td>
<Td> cell 4 </td>
<Td> cell 5 </td>
<Td> cell 6 </td>
</Tr>
</Table>
<Input type = "button" onclick = "setColSpan ()" value = "Change colspan value">


// In js, The setInterval (infinite bullet) function and the corresponding stop function are called cyclically.
Var timer // first declare a variable to store setInterval returned

.
Timer = setInterval ("alert ('000000')", 123); // store the value returned by setInterval with declared variables.
ClearInterval (timer); // clears the setInterval Function
If you want to call a parameter in the setInterval method and the function needs to pass the parameter, you can declare the value to be passed as a global variable by using the following method:

And then call it in the method. For example:
<Script type = "text/javaScript">
Var n = 1, obj;
Function f1 ()
{Obj = setInterval (f2(), 1000 )}
Function f2 ()
{Alert (n + = n ;)}
</Script>



// Js to obtain the URL of this page
Var Url = window. location. href;


// Save this page under js Control
Document.exe cCommand ("SaveAs", "", "C: \ index.htm"); // 1. name of the operation to be performed, 2. the address, file name, and file type saved by default.
Function save (dizhi ){
Document.exe cCommand ("SaveAs", "", dizhi );
}


// Open, save as, attribute, print, and other 14 JS Code
■ Enable ■
<Input name = Button onClick = document. all. WebBrowser. ExecWB (1,1) type = button value = open>
<OBJECT classid = CLSID: 8856F961-340A-11D0-A96B-00C04FD705A2 height = 0 id = WebBrowser width = 0> </OBJECT>
■ Save As ■
<Input name = Button onClick = document. all. WebBrowser. ExecWB (4,1) type = button value = Save As> <OBJECT

Classid = CLSID: 8856F961-340A-11D0-A96B-00C04FD705A2 height = 0 id = WebBrowser width = 0> </OBJECT>
■ Attribute ■
<Input name = Button onClick = document. all. WebBrowser. ExecWB (10, 1) type = button value = property> <OBJECT

Classid = CLSID: 8856F961-340A-11D0-A96B-00C04FD705A2 height = 0 id = WebBrowser width = 0> </OBJECT>
■ Print ■
<Input name = Button onClick = document. all. WebBrowser. ExecWB (6, 1) type = button value = print> <OBJECT

Classid = CLSID: 8856F961-340A-11D0-A96B-00C04FD705A2 height = 0 id = WebBrowser width = 0> </OBJECT>
■ Page settings ■
<Input name = Button onClick = document. all. WebBrowser. ExecWB (8, 1) type = button value = page Settings> <OBJECT

Classid = CLSID: 8856F961-340A-11D0-A96B-00C04FD705A2 height = 0 id = WebBrowser width = 0> </OBJECT>
■ Refresh ■
<Input type = button value = refresh name = refresh onclick = "window. location. reload ()">
■ Import to favorites ■
<Input type = "button" name = "Button" value = "Import favorites" onClick = window. external. ImportExportFavorites (true,);>
■ Export to favorites ■
<Input type = "button" name = "Button3" value = "Export favorites" onClick = window. external. ImportExportFavorites (false,);>
■ Add to favorites ■
<INPUT name = Button2 onclick = "window. external. AddFavorite (location. href, document. title)" type = button value = add to favorites

Folder>
■ Sort favorites ■
<INPUT name = Submit2 onclick = "window. external. ShowBrowserUI (OrganizeFavorites, null)" type = button value = favorites>
■ View the original file ■
<INPUT name = Button onclick = window. location = "view-source:" + window. location. href type = button value = view source File>
■ Language settings ■
<INPUT name = Button onclick = "window. external. ShowBrowserUI (LanguageDialog, null)" type = button value = language Settings>
■ Qianjin ■
<INPUT name = Submit onclick = history. go (1) type = submit value = forward>
■ Retreat ■
<INPUT name = Submit2 onclick = history. go (-1) type = submit value = back>


// Change the CSS style
1. Change the local style (case sensitive)
Change className (style is not required)
Document. getElementById ('t2'). className = "..."
Change classText (style is required)
Document.getElementById('t2').style.css Text = "..."
Directly change the CSS style of the control
Document. getElementById ('t2'). style. backgroundColor = "#003366 ″
Ii. Global style change (skin replacement)
Add an id to the currently used CSS style. During skin replacement, change the referenced CSS style path, for example:
<Link rel = "stylesheet" type = "text/css" id = "css" href = "firefox.css"/>
<Span on click = "javascript: document. getElementById ('css '). href = 'ie.css'"> click here to change the style </span>

7.
// Generate a random number. The parameter is (minimum value, maximum value)
Function GetRnd (min, max ){
Return parseInt (Math. random () * (max-min + 1 ));
}

Bytes
// Convert a string to a number in js
ParseInt ("123"); // 123

Related Article

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.