Home > Web Front-end > JS Tutorial > Some minor problems encountered when writing js_javascript skills

Some minor problems encountered when writing js_javascript skills

WBOY
Release: 2016-05-16 18:14:16
Original
1054 people have browsed it

1. When writing the OnClientClick event of , you need to add return; otherwise, OnClientClick will return false, but the OnClick event will still be executed.
For example:

Copy code The code is as follows:



2. When opening a new window using window.showModalDialog(), if it contains a js editor or other third-party editor, you will not be able to edit it, and you will not even be able to select it;
So far I have not If you find a better solution, try switching to window.open() method.
3. Checkbox all selection questions:
html:
Copy code The code is as follows:

Select all


js:
Copy code The code is as follows:

function selectAll()
{
var obj = document.getElementById("chkAll");
var ckblist = document.getElementById("ckblist" );
var chk = ckblist.getElementsByTagName("input");
if(obj.checked)
{ 🎜> {
 { 🎜>

Copy code


The code is as follows:


//js gets the Table and changes its style






< tr>





Cell 1 Cell 2
Cell 3 Cell 4 Cell 5



//The timed loop in js calls the function setInterval (infinite bomb) and the corresponding stop function
var timer //First, declare a variable to store setInterval and return

value.
timer=setInterval("alert('123')",500); //Use declared variables to store the value returned by setInterval.
clearInterval(timer); //Clear setInterval Function
If you really want to call parameters in the setInterval method, and the function needs to pass parameters, you can do it in the following way: declare the value to be passed as a global variable, and then

do it in the method Call. For example:




//js gets the URL of this page
var Url = window.location.href;


//js control to save this page
document.execCommand("SaveAs","","C:\index.htm") ; //1. The name of the operation to be performed, 2. The default save address, file name and file type
function save(dizhi){
document.execCommand("SaveAs","",dizhi);
}


//Open, save as, attribute, print" and other 14 JS codes
■Open■


■Save as■

classid=CLSID:8856F961 -340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0>

■Properties■

classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0>

■Print■

classid=CLSID:8856F961-340A -11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0>

■Page Settings■

classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0>

■Refresh■

■Import favorites■

■Export Favorites■

■Add to Favorites■

Folder>
■Organize Favorites■

■View original file■

■Language Settings■

■Forward■

■Back■



//Change CSS style
1. Partially change the style (case sensitive)
Change className (no need to add style)
document. getElementById('t2').className=”…”
Change classText (must add style)
document.getElementById(’t2’).style.cssText=”…”
Change the CSS of the control directly Style
document.getElementById('t2').style.backgroundColor=”#003366″
2. Globally change the style (skin change)
Add an id to the currently used CSS style and change the skin When changing the path of the referenced CSS style, for example:

< span on click="javascript:document.getElementById('css').href = 'ie.css'">Click me to change the style


//Generate random numbers , the parameters are (minimum value, maximum value)
function GetRnd(min,max){
return parseInt(Math.random()*(max-min 1));
}


//Convert strings to numbers in js
parseInt("123"); //123
Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template