Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我的jquery代码运行时没有点击,我的意思是刷新页面后,我应该在其中更改什么_Javascript_Jquery_Onclick_Refresh - Fatal编程技术网

Javascript 我的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(/^\//,'') &

我的jquery代码运行时没有点击,我的意思是刷新页面后,我应该在其中更改什么

<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代码不用点击就可以运行
但它显然是用点击运行的我和你想的一样,但在页面加载后它不用点击就可以运行,我不知道为什么一定有其他东西在运行,因为这段代码不用点击就不能运行