javascript对utl进行编码方法
场景:
有时候需要通过js进行url的编码,那么我们直接调用js自身的函数进行编码
实现:
<script type="text/javascript"> var imageUrl="http://www.someabcd.com/get.php?fid=11 "; alert(encodeURIComponent(imageUrl)); document.write(encodeURIComponent(imageUrl)); </script>
场景:
有时候需要通过js进行url的编码,那么我们直接调用js自身的函数进行编码
实现:
<script type="text/javascript"> var imageUrl="http://www.someabcd.com/get.php?fid=11 "; alert(encodeURIComponent(imageUrl)); document.write(encodeURIComponent(imageUrl)); </script>