zoukankan      html  css  js  c++  java
  • jquery对url中的中文解码

    项目中要实现一个select选择器选择后跳转url,并保存selected的值。

    url是用get来传递参数,所以考虑加载新页面时,读取参数值,并赋值到select中。

    但是由于url的参数使用的是中文,select不识别,所以通过jquery现成的转码函数,一句话搞定~!

    select选中值的防刷新:
    每次加载页面后读取url中的参数值,然后设定select的选中值,由于url中包含中文,使用了jquery的解码函数,
    
    var myurl=new LG.URL(window.location.href);//js封装的url操作函数
    $("#yewu").val(decodeURIComponent(myurl.get("yewu")));//jquery解码函数
    Encode URL String
    
    <script>
    var url = $(location).attr('href'); //get current url
    //OR
    var url = 'folder/index.html?param=#23dd&amp;noob=yes'; //or specify one
    
    var encodedUrl = encodeURIComponent(url);
    console.log(encodedUrl);
    
    //outputs folder%2Findex.html%3Fparam%3D%2323dd%26noob%3Dyes
    </script>
    
    
    Decode URL String
    
    <script>
    var url = $(location).attr('href'); //get current url
    //OR
    var url = 'folder%2Findex.html%3Fparam%3D%2323dd%26noob%3Dyes'; //or specify one
    
    var decodedUrl = decodeURIComponent(url);
    console.log(decodedUrl);
    //outputs folder/index.html?param=#23dd&amp;noob=yes
    </script>
  • 相关阅读:
    <Redis开发与运维> 阅读笔记
    请求行,请求头,请求体详解
    char 与 varchar 的区别
    python字符串的常用方法。
    快速排序的代码及原理
    C#之Dictionary源码
    C#中构造函数
    U3D——单例模式的用法
    U3D学习——设置VS2019作为开发工具
    U3D学习——脚本运行周期
  • 原文地址:https://www.cnblogs.com/woodk/p/4587490.html
Copyright © 2011-2022 走看看