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:
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:
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
Cell 1
Cell 2
< tr>
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■
■Properties■
■Print■
■Page Settings■
■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
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