//定義"隱藏內容"的函數
function hidden_txt(){
txt.style.display="none";
}
//定義"顯示內容"的函數
function show(){
txt.style.display="block";
}
//定義"取消設置"的函數
function cancle(){
var conf = confirm("是否取消設置");
if(conf){
txt.removeAttribute("style");
}
function hidden_txt(){
txt.style.display="none";
}
//定義"顯示內容"的函數
function show(){
txt.style.display="block";
}
//定義"取消設置"的函數
function cancle(){
var conf = confirm("是否取消設置");
if(conf){
txt.removeAttribute("style");
}
<script type="text/javascript">
txt=document.getElementById("txt");
//定義"改變顏色"的函數
function changeColor(){
txt.style.color="red";
txt.style.backgroundColor="blue";
}
//定義"改變寬高"的函數
function changeShape(){
txt.style.width="100px";
txt.style.height="100px";
}
txt=document.getElementById("txt");
//定義"改變顏色"的函數
function changeColor(){
txt.style.color="red";
txt.style.backgroundColor="blue";
}
//定義"改變寬高"的函數
function changeShape(){
txt.style.width="100px";
txt.style.height="100px";
}
<script type="text/javascript">
var mystr="我是";
var mychar="JavaScript";
document.write(mystr+"<br>");
document.write(mystr+mychar+"的忠實粉絲");
</script>
var mystr="我是";
var mychar="JavaScript";
document.write(mystr+"<br>");
document.write(mystr+mychar+"的忠實粉絲");
</script>
2015-11-30
function openWindow(){
var conf=confirm("是否打開新窗口");
if(conf==true){
var prom=prompt("輸入網址","http://www.xianlaiwan.cn/code/1642");
window.open('prom','imooc_blank','width=400,height=500,menubar=no,toolbar=no');
}
}
var conf=confirm("是否打開新窗口");
if(conf==true){
var prom=prompt("輸入網址","http://www.xianlaiwan.cn/code/1642");
window.open('prom','imooc_blank','width=400,height=500,menubar=no,toolbar=no');
}
}
1. 在JS中區分大小寫,如變量mychar與myChar是不一樣的,表示是兩個變量。
2. 變量雖然也可以不聲明,直接使用,但不規范,需要先聲明,后使用。
2. 變量雖然也可以不聲明,直接使用,但不規范,需要先聲明,后使用。
2015-11-29
1-6、注釋很重要
1、單行注釋,在注釋內容面前加符號"//"
2、多行注釋以"/"開始,以"/"結束。
1、單行注釋,在注釋內容面前加符號"//"
2、多行注釋以"/"開始,以"/"結束。
2015-11-29
養成良好的編程習慣,別忘記在語句末尾添加分號";",";"分號要在英文狀態下輸入。
2015-11-29
javascript可以放在html文檔的任意位置,可是由于html文檔的解析從上到下開始,所以建議放在head中以提前執行
2015-11-29
<title>插入js代碼<//title>
<script type="text/javascript">
document.write("開啟JS之旅!");
</script>
<script type="text/javascript">
document.write("開啟JS之旅!");
</script>
2015-11-29
第八行
var score=prompt("input your score"); //score變量,用來存儲用戶輸入的成績值。
似乎沒第九行再輸入的事情啊,
var score=prompt("input your score"); //score變量,用來存儲用戶輸入的成績值。
似乎沒第九行再輸入的事情啊,
2015-11-29
function openWindow(){
var ale = confirm('是否彈出新窗口?');
if(ale == true){
var openwin = prompt('請輸入你要打開的網址', 'http://www.xianlaiwan.cn/');
if(openwin == openwin){
window.open(openwin,'_blank','width=400,height=500,menubar=no,toolbar=no');
};
};
}
var ale = confirm('是否彈出新窗口?');
if(ale == true){
var openwin = prompt('請輸入你要打開的網址', 'http://www.xianlaiwan.cn/');
if(openwin == openwin){
window.open(openwin,'_blank','width=400,height=500,menubar=no,toolbar=no');
};
};
}