-
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" Content="text/html; charset=utf-8" />
<title>js入门编程挑战2</title>
<style type="text/css">
body{font-size:12px;}
#txt{
height:400px;
width:600px;
border:#333 solid 1px;
padding:5px;
}
p{
line-height:18px;
text-indent:2em;}
</style>
</head>
<body>
<h2 id="con">JavaScript课程</H2>
<div id="txt">
<h5>JavaScript为网页添加动态效果并实现与用户交互的功能。</h5>
<p>1. JavaScript入门篇,让不懂JS的你,快速了解JS。</p>
<p>2. JavaScript进阶篇,让你掌握JS的基础语法、函数、数组、事件、内置对象、BOM浏览器、DOM操作。</p>
<p>3. 学完以上两门基础课后,在深入学习JavaScript的变量作用域、事件、对象、运动、cookie、正则表达式、ajax等课程。</p>
</div>
<form>
<!--当点击相应按钮,执行相应操作,为按钮添加相应事件-->
<input type="button" value="改变颜色" onclick="change_color()">
<input type="button" value="改变宽高" onclick="change_wight()">
<input type="button" value="隐藏内容" onclick="display_off()">
<input type="button" value="显示内容" onclick="display_on()">
<input type="button" value="取消设置" onclick="cancle_op()">
</form>
<script type="text/javascript">
//定义"改变颜色"的函数
var comment=document.getElementById("txt")
// 保存原始样式
var originalStyles = {
color: comment.style.color,
backgroundColor: comment.style.backgroundColor,
width: comment.style.width,
height: comment.style.height,
display: comment.style.display
};
function change_color() {
comment.style.color="red";
comment.style.backgroundColor ="blue";
}
//定义"改变宽高"的函数
function change_wight() {
comment.style.width="300px";
comment.style.height="200px";
}
//定义"隐藏内容"的函数
function display_off() {
comment.style.display="none";
}
//定义"显示内容"的函数
function display_on() {
comment.style.display="block";
}
//定义"取消设置"的函数
function cancle_op() {
var is_cancel=confirm("是否取消设置?");
if(is_cancel)
{
comment.style.color=originalStyles.color;
comment.style.backgroundColor =originalStyles.backgroundColor;
comment.style.width=originalStyles.width;
comment.style.height=originalStyles.height;
comment.style.display=originalStyles.display;
}
}
</script>
</body>
</html>
查看全部 -
在 JavaScript 中,可以使用 var、let 和 const 关键字来声明变量。
var:ES5 引入的变量声明方式,具有函数作用域。
let:ES6 引入的变量声明方式,具有块级作用域。
const:ES6 引入的常量声明方式,具有块级作用域,且值不可变。
查看全部 -
Object.style.property=new style;
Object.style.display="none"/"block";
Object.className="new name";
例如:con.style.backgroundColor="red";
backgroundColor
height
width
color
font
fontFamily
fontSize
查看全部 -
Object.innerHTML 用于获取 或 替换HTML元素的内容
查看全部 -
window.open('href','_blank','width=300,height=200,menubar=no,toolbar=no, status=no,scrollbars=yes')
mywin.close();关掉窗口
查看全部 -
alert()弹出消息提示框
confirm()弹出消息对话框,包括一个确定按钮,一个取消按钮
查看全部 -
document.write(mystr+mychar+"sssss"+"<br>"+" "+"ssss");
变量不用加“”,输出固定值加“”
查看全部 -
if(判断条件){
}
else if{
}
else{
}
查看全部 -
<script src="script.js"></script>引用外部JS文件
查看全部 -
document.geiElementById("id").style.color="blue"; 表示设置某个id颜色为蓝色
查看全部 -
代码好难
查看全部 -
function openWindow(){
var queren=confirm("确定打开吗?");
if(queren==true){
var myweb=prompt("请输入网址","http://www.imooc.com");
if(myweb!=null){
window.open(myweb,"_blank",'width=400,heigth=500,menubar=no,toolbar=no')
}
else{
alert("再见");
}
}
}
查看全部 -
不是一定要获取到id名,直接用也行,但document.getElementById()这个方法得记得,这个作业涉及前面未学过的方法--removeAttribute(),对于return(flase)和return(trun)一直不太理解。
查看全部 -
fun是函数
查看全部 -
window.open('','','') 打开窗口
查看全部 -
var a = prompt() 文本框提示框
查看全部 -
var a=confirm() 消息对话框
查看全部 -
alert() 输出提示框
document.write() 输出流
查看全部 -
第一种:输出内容用""括起,直接输出""号内的内容。
第二种:通过变量,输出内容
第三种:输出多项内容,内容之间用+号连接。
第四种:输出HTML标签,并起作用,标签使用""括起来。
查看全部 -
document.write("hello");查看全部
-
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函数调用</title>
<script type="text/javascript">
function contxt() //定义函数
{
alert("哈哈,调用函数了!");
}
</script>
</head>
<body>
<form>
<input type="button" value="点击我" onclick=" contxt() " />
</form>
</body>
</html>
查看全部 -
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb18030">
<title>插入js代码</title>
<script type="text/javascript">
document.write("开启JS之旅!");
</script>
</head>
<body>
</body>
</html>
查看全部 -
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>热身</title>
</head>
<body>
<p id="p1">我是第一段文字</p>
<p id="p2">我是第二段文字</p>
<script type="text/javascript">
document.write("hello");
document.getElementById("p1").style.color="blue";
</script>
</body>
</html>
查看全部 -
getElementById是一个document对象的方法,可以通过它来获得指定id的html元素。
例如在页面里表单元素你可以给它设置id值,或name值来区别同种类型的不同元素,当你设置id document.getElementById("id")来得到这个元素,从而通过document.getElementById("id").value 得到元素的值。类似的方法还有document.getElementsByName("name")通过元素名称获得元素对象。document.getElementsByTagName("form")通过标签名称获得元素。
比如 <div id="test"></div>
document.getElementById("test") 就可以获取到这个对象了
查看全部
举报