在www.mysite.com/#i

编程入门 行业动态 更新时间:2024-10-23 21:32:06
本文介绍了在www.mysite/#i-bc中删除斜线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在主页上的某个特定div上选择更改事件。我希望像> www.mysite#i-bc 这样的结果,但在它们之间添加了诸如 www.mysite/#i-bc之类的结尾斜杠。我想删除使用jquery或其他东西的尾部斜线。这里是我的代码: 脚本: $ $ p $ $ $ $(function( ){ $('。toggle-view')。on('change',function(){ var url = $(this).val(); $ b $ if if(url) { window.location.hash = url; } return false; }); });

我的html是这样的:

< select class =toggle-view> < option value =#i-bc> 1< / option> < option value =#i-st> 2< / option> < option value =#i-mm> 3< / option> < option value =#i-cc> 4< / option> < / select> < div id =i-bc>一些内容在这里< / div> < div id =i-st>一些内容在这里< / div> < div id =i-mm>一些内容在这里< / div> < div id =i-cc>一些内容在这里< / div>

感谢InAdvance

解决方案

更好地使用 window.location.hash 。它优于 href

<脚本> $(function(){$('。toggle-view')。on('change',function(){var url = $(this).val(); if(url){window.location.hash = url ;} return false;});}); < / script>

I want to go to a particular div on my home page itself when select on change event. I want result like www.mysite#i-bc but trailing slash added in between them like www.mysite/#i-bc. I want to remove that trailing slash using jquery or something else. here is my code:

Script:

$(function(){ $('.toggle-view').on('change', function () { var url = $(this).val(); if (url) { window.location.hash = url; } return false; }); });

My html is like this:

<select class="toggle-view"> <option value="#i-bc">1</option> <option value="#i-st">2</option> <option value="#i-mm">3</option> <option value="#i-cc">4</option> </select> <div id="i-bc">some content here </div> <div id="i-st">some content here </div> <div id="i-mm">some content here </div> <div id="i-cc">some content here </div>

Thanks InAdvance

解决方案

Better use window.location.hash. Its better than href

<script> $(function(){ $('.toggle-view').on('change', function () { var url = $(this).val(); if (url) { window.location.hash = url; } return false; }); }); </script>

更多推荐

在www.mysite.com/#i

本文发布于:2023-11-01 11:58:59,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:www   mysite

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!