0
0

More than 1 year has passed since last update.

javascript演習 〜17日目/30日

Last updated at Posted at 2021-11-06

覚えたこと

localstorageに保存するには文字列に一旦変換する必要がある。
データを取得するには、取得した文字列データをJSON形式に戻す。

localStorage.setItem('items', JSON.stringify(items))

const items = JSON.parse(localStorage.getItem('items')) || [];

クリックした要素がinputなら除外する。

itemsList.addEventListener('click', (e) => {
  if(!e.target.matches('input')) return;

})

ES6 Destructuring

itemsList.addEventListener('mousemove', (e) => {
  let { offsetX: x, offsetY: y } = e;

})

hover要素が子要素に当たった時に、mousemoveのoffsetが子要素の数値に変わってしまうのを修正

itemsList.addEventListener('mousemove', (e) => {
  let { offsetX: x, offsetY: y } = e;

  if(this !== e.target){
    x = x + e.target.offsetLeft;
    y = y + e.target.offsetTop;
  }
})

正規表現とreplaceで冠詞を取り除く

function strip(bandName) {
  return bandName.replace(/^(a |the |an )/i, '').trim();
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0