JavaScript
var str = ‘hello sarahshine!‘;
console.log(str.slice(3)); // ‘lo sarahshine!‘
console.log(str.substring(3)); // ‘lo sarahshine!‘
console.log(str.subtr(3)); // ‘lo sarahshine!‘
var str = ‘hello sarahshine!‘;
console.log(str.slice(3,7)); // ‘lo s‘
console.log(str.substring(3,7)); // ‘lo s‘
console.log(str.substr(3,7)); // ‘lo sara‘
var str = ‘hello sarahshine!‘; //length = 17
//只傳入一個負數
console.log(str.slice(-3)); // ‘ne!‘ 相當於str.slice(14)
console.log(str.substring(-3)); // ‘hello sarahshine!‘ 相當於str.substring(0)
console.log(str.substr(-3)); // ‘ne!‘ 相當於str.substr(14)
//傳入兩個負數
console.log(str.slice(-3, -1)); // ‘ne‘ 相當於str.slice(14,16)
console.log(str.substring(-3, -1)); // ‘‘ 相當於str.substring(0,0)
console.log(str.substr(-3, -1)); // ‘‘ 相當於str.substr(14,0)
//傳入一正一負
console.log(str.slice(3, -4)); // ‘lo sarahsh‘ 相當於str.slice(3,13)
console.log(str.substring(3, -4)); // ‘hel‘ 相當於str.substring(3,0) 即(0,3)
console.log(str.substr(3, -4)); // ‘‘ 相當於str.substr(3,0)
Html產生按鈕後,js設定彈跳視窗顯示字幕 function()代入任意字元,便可使用console追蹤按鈕點入詳情,同時在多種的事件語法中,可提供紀錄匯出資料,是很重要的紀錄功能。 e.target用法 簡述:觸發事件就我們的印象中是帶入參數,傳遞從html來的特定欄位值,然而在原生的JS寫法,時常利用function(e){}預設的e去取得被點擊區塊的詳細資訊,而常使用e.target取得內部元素資料 案例 詳述:當要刪除經由迴圈產生出的列表時,就可以使用e.target確認id編號,再經由迴圈比對編號知道序號index,再splice刪除。
Oct 7, 2020前言:時常用於“我的最愛”功能列,一般我們所點選的資料都會藉由傳入後端資料庫儲存,如要取用也須從資料庫取出,無形中會增加資料庫的負荷,要節省儲存庫的容量以及載入速度,建議使用localStorage、cookie、sessionStorage的方式在瀏覽器儲存。 localStorage語法範例 存入方法:setItem("key位置",宣告) 取得方法:getItem('key位置') 匯入流程 先定義btn與html的ID位置,代入監聽公式,再建立function事件寫入匯入的公式(同上)
Oct 6, 2020解說傳值、傳參考 應對方式:Object.assign 操作實例 openModal(item){ //this.tempProduct= item; //因為物件傳參考的特性,直接用item會與tmepProduct相同 this.tempProduct= Object.assign({},item); //可採用es6語法,將item傳自獨立的空物件裡,才不會互相渲染 },
Sep 13, 2020vue元件階層處理方式 父子階層可透過emit及props做傳遞 如非父子層的關係,同階層就得經由eventbus傳遞,不過僅適合在較輕量的專案,因過多易混亂難以管理 也能選擇全域變數,但資料無法資料綁定 於是vuex就是為了解決元件層級傳遞的複雜性而被開發出,不論在層級位置都能互相傳遞,也能有雙向綁定的特性 總結使用時機
Sep 9, 2020or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up