<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>链接处理转义字符</title> <style> body{text-align: center;} textarea{width: 60%;height:180px;border: 2px solid #ccc;display: block;margin: 10% auto 0;padding: 0.5em;outline: none;box-shadow: 0;transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;} textarea:focus{border: 2px solid #80bdff;box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);} .btn {display: inline-block;font-weight: 400;color: #212529;text-align: center;vertical-align: middle;-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;background-color: transparent;border: 1px solid transparent;padding: .375rem .75rem;font-size: 1rem;line-height: 1.5;border-radius: .25rem;cursor: pointer;margin: 20px auto;box-sizing: border-box;transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;} .btn-primary {color: #fff;background-color: #007bff;border-color: #007bff;} btn-primary:hover {color: #fff;background-color: #0069d9;border-color: #0062cc;} </style> <script language="javascript"> function attEvt(evtName, fn) { if (window.attachEvent) window.attachEvent('on' + evtName, fn); else window.addEventListener(evtName, fn, false); } // attEvt('load', function () { // var as = document.getElementsByTagName("A"); // for (var i = 0; i < as.length; i++) { // var a = as[i]; // a.href = decodeURIComponent(a.href); // } // document.getElementById("txt").value = a.href; // }); </script> </head> <body> <!-- <a href="http://yhqtb.vip/mybook/#/chapter/%E6%88%91%E5%9C%A8%E4%B8%9C%E5%8C%97%E5%BD%93%E7%89%B9%E5%B7%A5/%E7%AC%AC2%E7%AB%A0%E7%81%AD%E5%8F%A3"> </a> --> <textarea name="" id="txt" cols="30" rows="10"> http://book.yhqtb.vip/#/chapter/%E6%88%91%E5%9C%A8%E4%B8%9C%E5%8C%97%E5%BD%93%E7%89%B9%E5%B7%A5/%E7%AC%AC2%E7%AB%A0%E7%81%AD%E5%8F%A3 </textarea> <button class="btn btn-primary" id="button">转换↓</button> <textarea id="decodeURI" cols="30" rows="10" placeholder="转换后的链接" style="margin-top:20px;" ></textarea> <button class="btn btn-primary" id="copy">复制</button> <script> window.onload = function(){ var btn = document.getElementById('button'); var copy = document.getElementById('copy'); var decodeURI = document.getElementById("decodeURI"); btn.addEventListener('click',function(){ var inlink = document.getElementById('txt').value.replace(/\s+/g,""); decodeURI.value = decodeURIComponent(inlink); }); copy.addEventListener('click',function(){ decodeURI.focus(); decodeURI.select(); document.execCommand("copy", true, null); // decodeURI.blur(); }) } </script> </body> </html> 提示:你可以先修改部分代码再运行。 转载请注明:有爱前端 » 链接处理转义字符(%3A%2F) 喜欢 (82)or分享 (0)