第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

localstorge本地存儲(chǔ)的一個(gè)小小個(gè)人例子

標(biāo)簽:
JavaScript

这个是我个人生活中的一个小小的案例,由于我最近在找工作,投的简历多了,就很容易弄混淆,我就弄了这个个小东西。

最开始没有实现本地存储的功能的,只是当作一个闭包的案例,具体看这里,但是这样子,一刷新,就会消失不见了,所以我就加入了一个本地存储的功能

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <form>
        <input type="text" name="" id="text">
        <input type="submit" name="" value="添加" id="button">
    </form>
    <ol id="box">
    </ol>
    <script type="text/javascript">
    // 获取页面元素
     function GetId(id) {
        return document.getElementById(id)
    }
    var button = GetId("button")
    var text = GetId("text")

    function getLocalStorage (){
        var hasPay_ArrayList = localStorage.getItem("isPayLocal")==""||localStorage.getItem("isPayLocal")=="null"||localStorage.getItem("isPayLocal")==null?[]:localStorage.getItem("isPayLocal").split(","),
            value = text.value
            console.log(hasPay_ArrayList)
        if(hasPay_ArrayList.length){
            for (var i = hasPay_ArrayList.length - 1; i >= 0; i--) {
            var li = document.createElement('li')
            li.innerHTML = hasPay_ArrayList[i] + '<br>'
            var box = GetId("box")
            box.appendChild(li)
            }
        }

    }
    getLocalStorage()

    button.addEventListener('click', function(e) {
        e.preventDefault()
        // 获取浏览器本地localStorage,可能是null,可能是“”
        var hasPay_ArrayList = (localStorage.getItem("isPayLocal")==""||localStorage.getItem("isPayLocal")=="null"||localStorage.getItem("isPayLocal")==null)?[]:localStorage.getItem("isPayLocal").split(",")

        console.log(hasPay_ArrayList)
        console.log(localStorage.getItem("isPayLocal"))
        var value = text.value;

        var isLive = hasPay_ArrayList.indexOf(value)>=0?true:false;
        console.log(isLive)

        if (value && !isLive) {
            var li = document.createElement('li')
            li.innerHTML = value + '<br>'
            var box = GetId("box")
            box.appendChild(li)
            text.value = ''
            var refreshLocalstorage = hasPay_ArrayList.push(value)
            localStorage.setItem("isPayLocal",hasPay_ArrayList)

            console.log(hasPay_ArrayList)
            console.log(localStorage.setItem("isPayLocal",hasPay_ArrayList))
        } else if (value&&isLive) {
            alert("已经投递")
        }else{
            alert("输入不能为空")
        }
        text.value=''
    })
    </script>
</body>

</html>

也是非常的简单的,当然还是可以自己去改变,多多的添加一些新的功能,让这个例子更加的完善,但是我目前就做了这么些的东西。出具雏形,以后再慢慢的添砖加瓦吧

點(diǎn)擊查看更多內(nèi)容
1人點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消