我想在主页上的某个特定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
发布评论