javascript Kendo UI:在按钮单击时获取 TextBox 值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16161662/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 03:31:01  来源:igfitidea点击:

Kendo UI: Get TextBox Value on Button Click

javascriptmvvmkendo-ui

提问by Hardik

I am having a form, which comprises of several textboxes and one button.

我有一个表单,其中包含几个文本框和一个按钮。

I am using the Kendo UI MVVM format. How shall I get the value of each textbox and store it in an object on click of the button?

我正在使用 Kendo UI MVVM 格式。我应该如何获取每个文本框的值并将其存储在单击按钮的对象中?

Will I have to use normal jQuery in order to get the values or is there some other way of getting the values from each of them?

我是否必须使用普通的 jQuery 才能获取值,还是有其他方法可以从每个值中获取值?

Thanks

谢谢

Hardik

哈迪克

回答by Dan

Please take a look at these documentation pages:

请查看这些文档页面:

http://demos.kendoui.com/web/mvvm/index.html
http://docs.kendoui.com/getting-started/framework/mvvm/observableobject
http://docs.kendoui.com/tutorials/mvvm-in-kendo-ui

http://demos.kendoui.c​​om/web/mvvm/index.html
http://docs.kendoui.c​​om/getting-started/framework/mvvm/observableobject
http://docs.kendoui.c​​om/tutorials/mvvm-剑道

These pages contain answers to most of the questions you'll have concerning Kendo UI MVVM. It would be silly and presumptuous of me to think that I could explain it better than the qualified and hard working individuals at Telerik that have so painstakingly compiled these documentation pages.

这些页面包含有关 Kendo UI MVVM 的大多数问题的答案。如果我认为我可以比 Telerik 的合格且努力工作的人更好地解释它,那将是愚蠢和冒昧的,他们如此煞费苦心地编译了这些文档页面。

The gist of it is that you need to create an instance of the kendo.data.ObservableObjectthat has properties for the values you are working with. This is your view-model. Then in your markup for your text boxes, include values for the data-bindattribute that reference the properties in your observable object. Create a function in your view-model to handle the button's clickevent. Put a data-bindattribute in your button that binds the click event to your function. Finally, call kendo.bind(<element>, <observable object>), and that will connect the wires from your markup to your view-model object.

它的要点是您需要创建一个kendo.data.ObservableObject具有您正在使用的值的属性的实例。这是您的视图模型。然后在文本框的标记中,包含data-bind引用可观察对象中属性的属性值。在您的视图模型中创建一个函数来处理按钮的click事件。data-bind在按钮中放置一个属性,将单击事件绑定到您的函数。最后,调用kendo.bind(<element>, <observable object>),这会将标记从您的标记连接到您的视图模型对象。

In your click event-handler, you can take the values of the view-model, and insert them into the object you need. You should not need to use "normal jQuery" for anything besides referencing the element to call bindon.

在您的单击事件处理程序中,您可以获取视图模型的值,并将它们插入到您需要的对象中。除了引用要调用的元素之外,您不需要对任何东西使用“普通 jQuery” bind

回答by jaredbaszler

Quickly you can retrieve the value this way using JQuery:

您可以使用 JQuery 以这种方式快速检索值:

$('#yourTextBoxID').data('kendoMaskedTextBox').value();

回答by Milad Doraki

you can use this code:

您可以使用此代码:

$('#yourTextBoxID').val();