Giter VIP home page Giter VIP logo

blog's Introduction

  • 👋 Hi, I’m @wzla
  • 👀 I’m interested in coding ...
  • 🌱 I’m currently learning JavaScript and C# ...
  • 💞️ I’m looking to collaborate on ...
  • 📫 How to reach me ...

blog's People

Contributors

wzla avatar

Watchers

 avatar

blog's Issues

使用原生JavaScript为元素添加CSS样式

const element = document.querySelector('#element');

//old
element.style.height = '100px';
element.style.color = '#ffffff';
element.style.backgroundColor = '#000000';

// new
Object.assign(element.style, {
	height: '100px',
  color: '#ffffff',
  backgroundColor: '#000000'
})

windows对象关系

// 当前window对象
const currentWindow = window;
// or
const selfWindow = window.self;

// 父级window
const parentWindow = window.parent;

// 顶级window:浏览器窗口
const topWindow = window.top;

使用原生API生成UUID

const uuid = window.crypto.randomUUID();
console.log(uuid);
// 'd4e2738c-f218-4dd4-a30f-0475f5ca3b9c'

window.location.search解析为对象

function getQueryStringArgs() {
    const qs = location.search.length > 0 ? location.search.substring(1): "",
          args = {};
    for (let items of qs.split("&").map(kv => kv.split("="))) {
        const name = decodeURIComponent(item[0]),
              value = decodeURIComponent(item[1]);
        if (name.length) {
            args[name] = value;
        }
    }
    return args;
}

New:

const paramsString = "q=URLUtils.searchParams&topic=api"
const searchParams = new URLSearchParams(paramsString);

for (let p of searchParams) {
  console.log(p);
}

searchParams.has("topic") === true; // true
searchParams.get("topic") === "api"; // true
searchParams.getAll("topic"); // ["api"]
searchParams.get("foo") === null; // true
searchParams.append("topic", "webdev");
searchParams.toString(); // "q=URLUtils.searchParams&topic=api&topic=webdev"
searchParams.set("topic", "More webdev");
searchParams.toString(); // "q=URLUtils.searchParams&topic=More+webdev"
searchParams.delete("topic");
searchParams.toString(); // "q=URLUtils.searchParams"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.