-
1. 改变HTML样式:对象.style.属性=新样式 例:mychar.style.backgroundColor="red"; 注意:backgroudColor、fontFamily、fontSize 等中的第二个单词要大写,color的C、family的F,因为在css里面写法是用短横杠连起两个单词的,如background-color。但把横杠去掉后,第二个单词要大写!查看全部
-
write就是在页面写点东西,写啥你随意。
getElementById,不理解不怕。
先看用了以后发生了什么。用了以后,第一段文字变成了蓝色。说明后面的“blue”将p1渲染成了蓝色。
所以,getElementById,从名字上直译:通过ID获取元素,ID就是p1。
获取了啥元素?把它的style的color元素拿出来,拿出来干嘛?让他等于“blue”。
查看全部 -
就是通过元素的ID查找到该元素。也就是查找到ID名为“p1”,从而来操作这个元素。比如:<p id="p1" > JavaScript使网页显示动态效果并实现与用户交互功能。</p>标签<p>是个段元素,它的ID是p1,getElementById(“p1”),就是找到这个段元素。后面的.style.color="blue";就是操作它了,更改颜色为蓝色。
查看全部 -
JavaScript-警告(alert 消息对话框)
语法:
alert(字符串或变量) 如果有多个alert语句,则按照顺序弹出消息框 1. 在点击对话框"确定"按钮前,不能进行任何其它操作。 2. 消息对话框通常可以用于调试程序。 3. alert输出内容,可以是字符串或变量,与document.write 相似。
查看全部 -
取消设置使用txt.removeAttribute("style") getAttribute、setAttribute和removeAttribute的详细说明: 参考: http://www.qingdou.me/2350.html查看全部
-
html的注释:<!--我是注释--> css和js多行的注释:/*我是注释*/ js单行的注释://我是注释
查看全部 -
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" Content="text/html; charset=utf-8" />
<title>javascript</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="changeColor()">
<input type="button" value="改变宽高" onclick="changeWidth()" >
<input type="button" value="隐藏内容 " onclick="changeHide()" >
<input type="button" value="显示内容" onclick="changeDisplay()">
<input type="button" value="取消设置" onclick="cancle()" >
</form>
<script type="text/javascript">
//定义"改变颜色"的函数
function changeColor(){
var a1=document.getElementById("con");
var a2=document.getElementById("txt");
a1.style.color = "red";
a2.style.backgroundColor = "#ccc";
}
//定义"改变宽高"的函数
function changeWidth(){
var a1=document.getElementById("con");
var a2=document.getElementById("txt");
a1.style.width = "10px";
a2.style.height = "15px";
}
//定义"隐藏内容"的函数
function changeHide(){
var a2=document.getElementById("txt");
a2.style.display = "none";
}
//定义"显示内容"的函数
function changeDisplay(){
var a2=document.getElementById("txt");
a2.style.display = "block";
}
//定义"取消设置"的函数
function cancle(){
var b=confirm("是否取消设置");
if(b==true){
document.getElementById("con").removeAttribute("style");
document.getElementById("txt").removeAttribute("style");
}
}
</script>
查看全部 -
JavaScript语句是发给浏览器的命令。这些命令的作用是告诉浏览器要做的事情。
查看全部 -
var tta = document.getElementById("txt")
//定义"改变颜色"的函数
function gcolor(){
tta.style.color='red';
tta.style.backgroundColor='#F0F8FF';
}
//定义"改变宽高"的函数
function gwidth(){
tta.style.widht='400px';
tta.style.height='500px';
}
//定义"隐藏内容"的函数
function gnone(){
tta.style.display="none";
}
//定义"显示内容"的函数
function gblock(){
tta.style.display="block";
}
//定义"隐藏显示为一体"的函数
function aat(){
tta.style.display = tta.style.display=="none"?"block":"none";
}
//定义"取消设置"的函数
function gcancel(){
var my = confirm("master,你真的忍心解除契约吗?")
if(my==true){
tta.removeAttribute('style');
alert("ma……master……")
}
else{
alert("真乖~~master")
}
}查看全部 -
var message=confirm("你确定要重置所有设置么?");
if(message==true){
txt.removeAttribute('style');查看全部 -
使用<script>标签在HTML网页中插入JavaScript代码。注意, <script>标签要成对出现,并把JavaScript代码写在
<script></script>
之间。查看全部 -
封装成对象试试查看全部
-
document.getElementById(“id”) 获取到的是整个对象 用document.getELementById().innerHTML;才可以获取到其中的内容查看全部
-
var openWindow = function(){ var url = 'http://www.imooc.com'; var a = confirm("是否要打开新的网页?"); if(a === true){ url = prompt('请输入你要打开的网址:',url); if(url != null){ window.open(url,'_blank','width=400,height=500,menubar=no,toolbar=no'); } } }查看全部
-
感觉这样比较好查看全部
举报