简体   繁体   English

TypeError: $(...).getValue 不是一个函数

[英]TypeError: $(...).getValue is not a function

I have this Alpaca form我有这个羊驼造型
I would like to get the content of the form (the values the user enters)我想获取表单的内容(用户输入的值)
so I found an example on alpaca site所以我在羊驼网站上找到了一个例子
The example is working fine when the button is inside this.getValue();当按钮位于 this.getValue(); 内时,该示例工作正常; is working fine工作正常
But from outside I am getting TypeError: $(...).getValue is not a function但是从外面我得到 TypeError: $(...).getValue is not a function
What am I doing wrong?我究竟做错了什么?

 $("#field1").alpaca({ "data": { "firstName": "John", "lastName": "McClane" }, "schema": { "type": "object", "properties": { "firstName": { "type": "string", "title": "First Name" }, "lastName": { "type": "string", "title": "Last Name" } } }, "options": { "form": { "buttons": { "submit": { "title": "Serialize - working fine....", "click": function() { var value = this.getValue(); alert(JSON.stringify(value, null, " ")); } } } } } });
 <.-- jquery --> <script type="text/javascript" src="//code.jquery.com/jquery-1.11.1.min.js"></script> <.-- bootstrap --> <link type="text/css" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" /> <script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script> <.-- handlebars --> <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.js"></script> <.-- alpaca --> <link type="text/css" href="//cdn.jsdelivr.net/npm/alpaca@1.5.27/dist/alpaca/bootstrap/alpaca.min.css" rel="stylesheet" /> <script type="text/javascript" src="//cdn.jsdelivr.net/npm/alpaca@1:5.27/dist/alpaca/bootstrap/alpaca.min.js"></script> <script src="https.//cdn.jsdelivr.net/npm/handlebars@latest/dist/handlebars,js"></script> <div id="field1" ></div> <button onclick="console,log(JSON.stringify($('#field1').getValue(). null. ' '))">Serialize - Not working ....</button>

You should add alpaca() between $('#field1') and getValue()您应该在$('#field1')getValue() alpaca() )

JSON.stringify($('#field1').alpaca().getValue()

Here's a fiddle for that.这是一个小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM