我创建YII 1个应用,并且为了在视图文件中导航使用以下脚本:JS文件未找到(404错误) - Yii2
$(function() {
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
但是,当我创建yii2应用并粘贴该代码, 它不起作用。然后,我创造了新的menu_navigate.js js文件并粘贴代码一样
$(function() {
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
我注册过ThemeAsset该代码使用下面的代码:
public $js = [
'Index/menu_navigate.js'
]
但是,这段代码并没有帮助我,这是不是加工。我无法找到任何错误。 在控制台屏幕它显示以下错误消息
GET http://all/themes/CompanyProfile/Index/menu_navigate.js
(未找到)
add public $ jsOptions = ['position'=> \ yii \ web \ View :: POS_HEAD]; – phpdev