Javascript 我的jquery代码运行时没有点击,我的意思是刷新页面后,我应该在其中更改什么
我的jquery代码运行时没有点击,我的意思是刷新页面后,我应该在其中更改什么Javascript 我的jquery代码运行时没有点击,我的意思是刷新页面后,我应该在其中更改什么,javascript,jquery,onclick,refresh,Javascript,Jquery,Onclick,Refresh,我的jquery代码运行时没有点击,我的意思是刷新页面后,我应该在其中更改什么 <script> ( function( $ ) { $(document).on('click', 'a[href*="#"]:not([href="#"])', function(e) { if (location.pathname.replace(/^\//,'') === this.pathname.replace(/^\//,'') &
<script>
( function( $ ) {
$(document).on('click', 'a[href*="#"]:not([href="#"])', function(e) {
if (location.pathname.replace(/^\//,'') === this.pathname.replace(/^\//,'') && location.hostname === this.hostname) {
var hashStr = this.hash.slice(1);
var target = $(this.hash);
target = target.length ? target : $('[name=' + hashStr +']');
if (target.length) {
$('html, body').animate({ scrollTop: target.offset().top -150 } , 1000);
window.location.hash = hashStr;
return false;
e.preventDefault();
}
}
});
}(jQuery));
</script>
(函数($){
$(文档)。在('click','a[href*=“#”]:而不是([href=”#“]),函数(e){
if(location.pathname.replace(/^\/,'')==this.pathname.replace(/^\/,'')和&location.hostname==this.hostname){
var hashStr=this.hash.slice(1);
var target=$(this.hash);
target=target.length?目标:$('[name='+hashStr+']');
if(目标长度){
$('html,body').animate({scrollTop:target.offset().top-150},1000);
window.location.hash=hashStr;
返回false;
e、 预防默认值();
}
}
});
}(jQuery));
我不太明白你的意思?你说我的jquery代码不用点击就可以运行
但它显然是用点击运行的我和你想的一样,但在页面加载后它不用点击就可以运行,我不知道为什么一定有其他东西在运行,因为这段代码不用点击就不能运行