所以我几个小时以来一直在尝试解决这个问题
这是我收到的错误:
我不明白是什么导致了错误,任何见解将不胜感激!
这是我的代码,忽略 smarty 语法:
<html>
<head>
<title>{$title}</title>
{include file='header/header.tpl'}
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container" style="padding-top: 5%;">
<form action="" method="POST">
<center>
<img src="" style="height: 70px;">
</center>
<div class="form-signin">
<input type="email" class="form-control" style="font-size: 10pt;" id="email" placeholder="Email Address" required autofocus>
<input type="password" class="form-control" style="font-size: 10pt;" id="password" placeholder="Password" required>
<input type="submit" class="btn btn-warning btn-sm" value="Login" data-loading-text"Login" id="login" onClick="login();" style="outline: none;">
</div>
</form>
</div>
{literal}
<script type="text/javascript">
$(function() {
function login() {
alert('asdf');
}
});
</script>
{/literal}
</body>
</html>
最佳答案
将登录移到就绪函数之外:
<script type="text/javascript">
$(function() {
function login() {
alert('asdf');
}
});
</script>
致:
<script type="text/javascript">
function login() {
alert('asdf');
}
</script>
问题是登录仅存在于就绪函数范围内。示例
function say() {
function hello() {
alert("hello");
}
// call hello inside the say scope
hello(); // this displays the alert
}
say(); // this will show the alert
hello(); // error function is not defined. because it is out of scope
关于Javascript onclick 对象不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25596018/