Js event handling and browser object sample introduction

  • 2020-03-30 00:39:37
  • OfStack

 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
<title> Simple event handling </title> 

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
<meta http-equiv="description" content="this is my page"> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> 

<!-- 
<script language="text/javascript" src="hello.html"> this js The external call tag cannot end itself </script> 
<link rel="stylesheet" type="text/css" href="./styles.css"> 
--> 
<script type="text/javascript"> 
function clickD(obj){ 
alert(obj.innerHTML); 
} 

function mouseD(obj){ 
obj.style.color = "#f00"; 
//When using code to set styles, if CSS is represented by -, you must use a hump to indicate font-size -> fontSize
obj.style.fontSize = "16px"; 
} 
function outD(obj){ 
obj.style.color = "#000"; 
obj.style.fontSize = "18px"; 
} 

//With the use of the
with(document){ 
write("dddd<br/>"); 
} 
document.write("aaaa<br/>"); 
document.write("bbbb<br/>"); 
document.write("cccc<br/>"); 
</script> 
</head> 

<body> 
<div onclick="clickD(this)" style="cursor:pointer;"> Click and try it </div> 
<div onmouseover="mouseD(this)" onmouseout="outD(this)"> Try moving the mouse </div> 

</body> 
</html> 

2. An example of a browser object
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" 
"http://www.w3.org/TR/html4/strict.dtd"> 


<html xmlns="http://www.w3.org/1999/xhtml" lang="en"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>js01_hello</title> 
<meta name="author" content="Administrator" /> 
<script type="text/javascript"> 
// setTimeout("endWelcome()",5000); 
// function endWelcome() { 
// document.getElementById("welcome").style.display = "none"; 
// } 
</script> 
</head> 
<body> 
<div id="welcome"> Welcome to our website </div> 
<a href="#" onclick="window.open('test02.html','aaa','width=300,height=300,resizable=0')">test02</a> 
<a href="#" onclick="window.open('test03.html','aaa','width=400,height=400,resizable=0')">test03</a> 
<br/> 
<a href="#" onclick="window.open('bless.html','aaa','width=600,height=300')"> Enter your blessing message </a> 
<a href="#" onclick="window.open('bless.html','aaa','width=600,height=300')"> Sex selection </a> 
<div id="bless"></div> 
</body> 
</html> 

 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" 
"http://www.w3.org/TR/html4/strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" lang="en"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>js01_hello</title> 
<meta name="author" content="Administrator" /> 
<script type="text/javascript"> 
function bless() { 
//Gets the message entered
var mb = document.getElementById("mb").value; 
//Gets the parent window
var p = window.opener; 
//Gets the div with the id bless in the parent window
var pd = p.document.getElementById("bless"); 
//Set the value of pd
pd.innerHTML = mb; 
//Close the current window
window.close(); 
} 
</script> 
</head> 
<body> 
 Enter a blessing message :<input type="text" size="40" id="mb"/><input type="button" onclick="bless()" value=" The input " /> 
</body> 
</html> 

Related articles: