PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

通过jQuery编码转换、事件响应、页面跳转实现浏览器跳转并传递参数

php中世界最好的语言
php中世界最好的语言 原创
2018-05-03 10:15:49 1338浏览

这次给大家带来通过jQuery编码转换、事件响应、页面跳转实现浏览器跳转并传递参数,通过jQuery编码转换、事件响应、页面跳转实现浏览器跳转并传递参数的注意事项有哪些,下面就是实战案例,一起来看一下。

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title></title>
  <script src="https://cdn.bootcss.com/jquery/2.2.2/jquery.slim.js"></script>
</head>
<body>
<input type="text" class="keyword"/>
<button id="searchBtn">点击</button>
<script type="text/javascript">
  $("#searchBtn").click(function() {
    var searchText = jQuery.trim($(".keyword").val());
    var searchUrl = encodeURI("two.html?searchText=" + searchText); //使用encodeURI编码
    location.href = searchUrl;
  })
</script>
</body>
</html>

two.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title></title>
  <script src="https://cdn.bootcss.com/jquery/2.2.2/jquery.slim.js"></script>
</head>
<body>
<input type="text" class="keyword1"/>
<script type="text/javascript">
  //获取 上一个搜索页面传来的参数 
  var searchUrl = window.location.href;
  var searchData = searchUrl.split("="); //截取 url中的“=”,获得“=”后面的参数
  var searchText = decodeURI(searchData[1]); //decodeURI解码
  $(".keyword1").val(searchText);
</script>
</body>
</html>

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

js获取ModelAndView后如何使用

vue中v-if与v-show使用方法与区别

jQuery实现输入文字超过规定行数时自动添加省略号

以上就是通过jQuery编码转换、事件响应、页面跳转实现浏览器跳转并传递参数的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。