URL编码和解码

<!-- run -->
<img src="https://readme-typing-svg.herokuapp.com/?lines=实用在线工具;URLEncode与URLDecode;&center=true&size=27">

<div>
  <h3>URL编码与解码</h3>
    <textarea name="origin-text" id="origin-text" cols="30" rows="10" placeholder="待编码URL"></textarea>
    <div style="display: flex;">
        <button id="encode-btn">编码🔽</button>
        <button id="decode-btn">解码🔼</button>
    </div>
    <textarea name="encode-text" id="encode-text" cols="30" rows="10" placeholder="已编码URL"></textarea>

    <script>
        window.onload = function() {
            var encodeBtn = document.getElementById('encode-btn')
            var decodeBtn = document.getElementById('decode-btn')

            encodeBtn.onclick = function() {
                var originText = document.getElementById('origin-text')
                var encodeText = document.getElementById('encode-text')
                encodeText.value = encodeURI(originText.value)
            }
            decodeBtn.onclick = function() {
                var originText = document.getElementById('origin-text')
                var encodeText = document.getElementById('encode-text')
                originText.value = decodeURI(encodeText.value)
            }
        }
    </script>
</div>
posted @ 2022-02-12 12:21  CoderWGB  阅读(172)  评论(0编辑  收藏  举报