Mobiscroll,识别触发它的元素

时间:2013-11-25 23:37:07

标签: javascript jquery mobiscroll

情境:

我有一个需要多次和选择选择器的表单,为了减少重复,我想出了一个时间只有2个隐藏输入而另一个选择选择器的计划,那么我有多个链接/按钮的类别为例如“triggerTime”

HTML:

<input class="hidden" id="timeSelect" />

<button class="triggerTime" id="btn1">Select time 1</button>
<button class="triggerTime" id="btn2">Select time 2</button>
<button class="triggerTime" id="btn3">Select time 3</button>

JavaScript的:

//triggering time picker
$('.triggerTime').click(function(e){
    e.stopPropagation();
    e.preventDefault();
    $('#timeSelect').mobiscroll('show');
    //$('#timeSelect').mobiscroll('trigger', name, $.makeArray(e));
});

//activating time picker
$('#timeSelect').mobiscroll().time({
    theme: 'ios7',
    display: 'bottom',
    mode: 'scroller',
    headerText: false,
    onSelect: function(valueText,inst) {
        console.log('onSelect',valueText,inst,this);
    },
    onShow: function(html, valueText, inst) {
        console.log('onShow',html,valueText,inst);
    },
    onBeforeShow: function (html, inst) {
    console.log('onBeforeShow',html,inst,this);
    }
});

问题:

有没有办法在“onSelect”期间传递触发mobiscroll的元素的信息?我需要知道哪个按钮触发了mobiscroll

组件版本:

  • Mobiscroll 2.8.2
  • Jquery 2.0.3

1 个答案:

答案 0 :(得分:0)

只有这样才能达到我想要的效果(无需额外激活)

$('.triggerTime').click(function(e){
    e.stopPropagation();
    e.preventDefault();
    var clickedElement = $(this);
    $('#timeSelect').mobiscroll({
            anchor: clickedElement,
            theme: 'ios7',
            display: 'bottom',
            mode: 'scroller',
            headerText: false,
            preset: 'time',
            onSelect: function (valueText,inst) {
                    clickedElement.html(valueText);
            }
    });
    $('#timeSelect').mobiscroll('show');
});