我在cordova中使用cordova,我的要求如下:
正如您所看到的,我希望从表单中存储我的inputs值:
在我的my-app.js里
// Initialize your app
var myApp = new Framework7();
// Export selectors engine
var $$ = Dom7;
// Add views
var view1 = myApp.addView('#view-1');
var view2 = myApp.addView('#view-2', {
// Because we use fixed-through navbar we can enable dynamic navbar
dynamicNavbar: true
});
var view3 = myApp.addView('#view-3');
var view4 = myApp.addView('#view-4');
var ptrContent = $$('.pull-to-refresh-content');
$$('.save-storage-data').on('click', function() {
var storedData = myApp.formStoreData('my-info-form', {
'name': 'John', // this value should be the input's value, I just write for test here
'address':'address', // this value should be the input's value, I just write for test here
'page':'page', // this value should be the input's value, I just write for test here
'tel':'139', // this value should be the input's value, I just write for test here
'email': 'john@doe.com', // this value should be the input's value, I just write for test here
'gender': 'female', // this value should be the input's value, I just write for test here
'isAcceptPushNotification': ['yes'], // this value should be the input's value, I just write for test here
'birthday': '' // this value should be the input's value, I just write for test here
});
alert('success')
});正如您所看到的,$$('.save-storage-data').on('click', function()函数是我想要的,我想将form信息保存到我的应用程序中。
另外,我应该判断是否所有的输入都充满了值,然后保存数据。
发布于 2016-12-21 05:36:42
让我们循环遍历所有表单输入字段,并在保存之前检查它们是否都已填充:
$$('.save-storage-data').on('click', function() {
$$('.save-storage-data input').each(function(i, obj) {
if (!$$(this).val()) {
myApp.alert("Please fill all the required fields.");
return false;
}
});
var storedData = myApp.formStoreData('my-info-form', {
'name': 'John', // this value should be the input's value, I just write for test here
'address':'地址', // this value should be the input's value, I just write for test here
'page':'page', // this value should be the input's value, I just write for test here
'tel':'139', // this value should be the input's value, I just write for test here
'email': 'john@doe.com', // this value should be the input's value, I just write for test here
'gender': 'female', // this value should be the input's value, I just write for test here
'isAcceptPushNotification': ['yes'], // this value should be the input's value, I just write for test here
'birthday': '' // this value should be the input's value, I just write for test here
});
alert('保存成功')
});https://stackoverflow.com/questions/41238674
复制相似问题