I erstellt yii 1 Anwendung und verwendet folgende Skript, um im Hinblick auf Datei zu navigieren:JS-Datei von AssetBundle nicht gefunden (Fehler 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;
}
}
});
});
Aber, wenn ich yii2 Anwendung erstellt und diesen Code eingefügt , Es hat nicht funktioniert. Dann habe ich erstellt neue menu_navigate.js js Datei und Einfügen Code wie
$(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;
}
}
});
});
i registriert diesen Code in ThemeAsset folgenden Code:
public $js = [
'Index/menu_navigate.js'
]
Aber dieser Code half mir nicht, und es ist nicht Arbeiten. Ich konnte keinen Fehler finden. In Konsolenbildschirm wird es zeigt folgende Fehlermeldung
GET http://all/themes/CompanyProfile/Index/menu_navigate.js
(nicht gefunden)
add public $ jsOptions = ['position' => \ yii \ web \ Ansicht :: POS_HEAD]; – phpdev