如何使用PhoneJS读取输入字段的值?

时间:2014-02-02 12:03:44

标签: javascript jquery mvvm phonejs

这是我的HTML:

<div data-options="dxView : { name: 'home', title: 'Home' } " >
<div class="home-view"  data-options="dxContent : { targetPlaceholder: 'content' } " >

    <input data-bind="dxTextBox: { value: username }" />
    <input data-bind="dxTextBox: { value: password }" />
    <div data-bind="dxButton: { text: 'Login', clickAction: validateLogin }"></div>
      </div>

这是我的JavaScript控制器

MyApp.home = function (params) {

var viewModel = {

    username: ko.observable(''),
    password: ko.observable(''),

    validateLogin : function ()
    {
        console.log(this.username());
        userNameTxt = this.username();
        alert(this.username());
    }
};

return viewModel;

};

文本字段的值未退出。空白消息正在被警告。

2 个答案:

答案 0 :(得分:1)

只需将警告“this”更改为“viewModel”即可。喜欢belo

MyApp.home = function (params) {

var viewModel = {

    username: ko.observable(''),
    password: ko.observable(''),

    validateLogin : function ()
    {
        console.log(this.username());
        userNameTxt = this.username();
        alert(viewModel.username());
    }
};

return viewModel;

};

答案 1 :(得分:-1)

userName: {
        value: ko.observable(""),
        valueUpdateEvent: 'keyup search',
        placeholder: "Username",

    },
    password: {
        value: ko.observable(""),
        mode: 'password',
        placeholder: "type a password",
        valueUpdateEvent: 'keyup search',
    },

检查