gpt4 book ai didi

javascript - 未捕获的类型错误 : undefined is not a function

转载 作者:行者123 更新时间:2023-12-03 12:07:05 24 4
gpt4 key购买 nike

我正在使用 Telerik Appbuilder HTML5 + javascript 制作一个简单的表单,该表单接受用户输入,并在用户单击提交按钮时将其记录到控制台。

ClientClass.js:

function Client() {
this.username = "username",
this.password = "Password",
this.printUsername = function() {
this.username=$("#Username").val()
console.log(this.username);
};
};

首页.html:

<div data-role="view" data-title="Login" data-layout="main" data-model="APP.models.login">
<script src="../scripts/ClientClass.js"></script>
<h1 data-bind="html: title"></h1>
<script src="../scripts/ClientClass.js"></script>
<script>
function printUsername() {
var client = new client();
client.printUsername();
}
</script>
<ul data-role="listview" data-style="inset">
<li>
<label>Username
<input type="text" value="" id="Username" />
</label>
</li>
<li>
<label>Password
<input type="password" value="" />
</label>
</li>
<li>
<label>
<button onclick="printUsername()" type="button">Submit</button>
</label>
</li>
</ul>

</div>

索引.html:

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<link href="kendo/styles/kendo.mobile.all.min.css" rel="stylesheet" />
<link href="styles/main.css" rel="stylesheet" />

<script src="cordova.js"></script>
<script src="kendo/js/jquery.min.js"></script>
<script src="kendo/js/kendo.mobile.min.js"></script>

<script src="scripts/app.js"></script>
<script src="scripts/ClientClass.js"></script>

</head>
<body>
<script src="scripts/ClientClass.js"></script>
<script src="scripts/ClientClass.js"></script>

<div data-role="layout" data-id="main">
<div data-role="header">
<div data-role="navbar">
<span data-role="view-title"></span>
</div>
</div>

<!-- application views will be rendered here -->

<label>
<input type="password" value="password" />
</label>

<div data-role="footer">
<div data-role="tabstrip">
<a href="views/home.html" data-icon="home">Home</a>
<a href="views/settings.html" data-icon="settings">Settings</a>
<a href="views/contacts.html" data-icon="settings">Contacts</a>
</div>
</div>
</div>

</body>
</html>

它在控制台中显示:

uncaught type error: undefined is not a function.

然后它说它位于 index.html#views/home.html:1 ,当我单击它时,它会将我带到调试器的源面板。它说源是 index.html 并且它说:

(function() {with (this[2]) {with (this[1]) {with (this[0]) {return function(event) {printUsername() }; }}}})

有人发现我的 html 或 javascript 有任何问题吗?或者我导入脚本的方式?谢谢

最佳答案

您将您的客户端声明为一个对象,而不是一个“类”。所以在你的对象上使用 new 没有多大意义。

所以这取决于你,或者你保留你的对象并简单地删除:

var client = new client();

或者你使用一个类

function Client(){}

关于javascript - 未捕获的类型错误 : undefined is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25136288/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com