在www.mysite.com/#i-bc中删除斜线 [英] Trailing slash remove in www.mysite.com/#i-bc
问题描述
我想在主页上的某个特定div上选择更改事件。我希望像> www.mysite.com#i-bc
这样的结果,但在它们之间添加了诸如 www.mysite.com/#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.com#i-bc
but trailing slash added in between them like www.mysite.com/#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-bc中删除斜线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!