• 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>
  • 相关阅读:
    Oracle基础知识
    tomcat服务器
    jquery实现常用UI布局
    css画布
    css布局
    jquery快速常用技能
    css快速浏览
    css选择器
    spring boot项目mybatis配置注解+配置文件
    sass的安装和基础语法
  • 原文地址:https://www.cnblogs.com/woodk/p/4587490.html
Copyright © 2020-2023  润新知