獲取對象的元素
var person={
? ? name:'wym',
? ? age:18
}
person.name//=>'wym';
person['name']//=>'wym'
“two”>"three"http://=>true;字母索引越大越大
當函數(shù)賦值給對象的屬性,我們稱之為方法
階乘
function factorial(n) {
?? var product = 1;
?? while (n > 1) {
? ? ?? product *= n;
? ? ?? n--;
?? }
?? return product;
}
var temp = factorial(10);
console.log(temp)//3628800
?
function factorial1(n) {
?? var i, product = 1;
?? for (i = 2; i <= n; i++) {
? ? ?? product *= i;
?? }
?? return product;
}
var temp1 = factorial1(10);
console.log(temp1)//3628800
瀏覽器調試快捷鍵:F12/ctrl+shift+J
三秒后點擊確定跳轉
?? <script>
? ? ?? function moveOn() {
? ? ? ? ?? var answer = confirm("Are you ready?");
? ? ? ? ?? if (answer) {//點確定后跳轉
? ? ? ? ? ? ?? window.location = "https://www.baidu.com/"
? ? ? ? ?? }
? ? ?? }
? ? ?? setTimeout(moveOn, 3000);
? ? ?? var str=prompt("輸入密碼:","password");
? ? ?? console.log(str)//顯示輸入的內容
?? </script>
三種彈窗方式
1、alert
只有一個參數(shù);顯示彈窗信息;無返回值。
2、comfirm
只有一個參數(shù);顯示彈窗信息;有返回值,點確定返回true,點取消返回false
3、prompt
有兩個參數(shù),第一個參數(shù)顯示提示欄信息,第二個參數(shù)顯示輸入框信息;有返回值,返回用戶輸入的內容;