我正在尝试在Google的Materializecss中调用M.toast()函数,但收到错误消息:
未捕获的ReferenceError:未定义M
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My App</title>
<link rel="stylesheet" type="text/css" href="styles/materialize.css">
<link rel="stylesheet" type="text/css" href="styles/style.css">
<script type="text/javascript" src="scripts/jquery-3.3.1.js"></script>
<script type="text/javascript" src="scripts/materialize.js"></script>
</head>
<body>
<form action="#">
<button class="waves-effect waves-light btn" id="submit" type="submit" name="submit">
Submit
</button>
</form>
<script type="text/javascript" src="scripts/register.js"></script>
</body>
</html>
register.js
(function() {
'use strict';
$('form').submit(
function(e) {
let $radio = $("input:radio[name='myradio']");
if (!$radio.is(':checked')) {
e.preventDefault();
toast();
return false;
}
});
function toast() {
M.toast({html: 'Bitte alle Felder auswählen!'});
}
})();
我忘了包括某些东西或什么事吗?
答案 0 :(得分:0)
解决方案:将MaterializeCSS更新为1.0.0版