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标签,并起作用,标签使用""括起来。
<!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") 就可以获取到这个对象了
open() 方法可以查找一个已经存在或者新建的浏览器窗口。
document.write() 可用于直接向 HTML 输出流写内容。简单的说就是直接在网页中输出内容。
js 当中 alert(字符串或变量); 是 alert弹出消息对话框(包含一个确定按钮)。
document.write() 插入数据
Object.style.display = value
value:none/block
Object.style.property=new style;
Object是获取的元素对象