jQuery Mobile自定义翻转框获取选定值 [英] JQuery Mobile Custom Flipbox get selected value
本文介绍了jQuery Mobile自定义翻转框获取选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Datebox jQM插件创建了以下customflipbox:
I have the following customflipbox created using the Datebox jQM plugin:
<div data-role="fieldcontain">
<label for="cf" data-i18n="config.localelabel"></label>
<input name="cf" type="date" data-role="datebox" id="cf" data-options='{"mode": "customflip",
"customData": [ {
"input": true,
"name": "",
"data": ["Italiano","English","Espanol","Deutsch","Francais","русский"]
}],
"useNewStyle": false,
"overrideStyleClass": "ui-icon-dice",
"useButton":false,
"useFocus" : true
}' />
当我选择一个值时,我需要使用所选值填充cf输入字段,我尝试过:
When I pick a value I need to populate the cf input field with the selected value, I tried:
$('cf').on('datebox',function(p,e){
if (p.method === 'set') {
e.stopImmediatePropagation();
$(this).val(selectdata[p.value]);
}
});
关于日期框"事件,但似乎我能获得的最多是该字段填充了所选值的索引,但我需要实际的字符串(例如英语).
on the 'datebox' event, but it seems the most i can get is that the field is populated with the index of the selected value but I need the actual string (e.g. English).
有见识吗?
谢谢. M.
推荐答案
在代码中添加数据数组,然后可以在'set'事件中引用它:
Add the data array in code and then you can reference it in 'set' event:
<div data-role="fieldcontain">
<label for="cf" data-i18n="config.localelabel"></label>
<input name="cf" type="date" data-role="datebox" id="cf" data-options='{"mode": "customflip",
"useNewStyle": false,
"overrideStyleClass": "ui-icon-dice",
"useButton":false,
"useFocus" : true
}' />
在代码中创建一个名为selectdata的全局变量,该变量是值的数组:
In code create a global variable called selectdata that is the array of values:
var selectdata = ["Italiano","English","Espanol","Deutsch","Francais","русский"];
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
'customData': [{
'input': true,
'name': '',
'data': selectdata
}],
"useHeader": false,
"overrideCustomSet": "OK"
});
$('#cf').on('datebox', function (e, p) {
if (p.method === 'set') {
e.stopImmediatePropagation();
$(this).val(selectdata[p.value]);
}
});
DEMO
这篇关于jQuery Mobile自定义翻转框获取选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文