2013-06-26 83 views
0

跳過滾動條以獲取點擊事件中的選定項。這是我做了什麼來獲取滾動條中選定項目的價值。如何獲取Mobiscroll點擊事件中滾動條項的值


$('#questions').mobiscroll().select({ 
    theme: 'wp', 
    accent: 'none', 
    display: 'modal', 
    tap : true, 
    // mode: 'mixed', 
    inputClass: 'i-txt', 
    setText : 'Select', 
    onSelect : function(valueText, inst){ selectedQuestion(valueText, inst); }, 
    onValueTap : function(item, inst){ tappedQuestion(item, inst); }, 
    width: 400 
}); 

    function selectedQuestion(valueText, inst){ 
    console.log($('#questions').val()); 
} 

function tappedQuestion(obj, inst){ 
    console.log("Old Value: "+$('#questions').val()); 
    console.log($(obj).val()); // this is NULL 
    var x = $(obj).get(0).dataset.val; // have to dig down to get the val of the item 
    console.log("Tapped val: "+x); // now i got the value 
    $('#questions').val(x); // set the Select option to selected 
    var tt = $(obj).get(0).innerText; // now getting the text of the selected option 
    $('.ui-btn-text > span.f-dd').text(tt); // now setting the display text 
    $('#questions').mobiscroll('hide'); // hiding the scroller 
    console.log("New Value of Select: "+$('#questions').val()); // checking we are good 
} 

下面是HTML。

<select name="questions" id="questions" data-theme="a" class="f-dd" > 
<option value="0">Opt 0</option> 
<option value="1">Opt 1</option> 
<option value="2">Opt 2</option> 
<option value="3">Opt 3</option> 
<option value="4">Opt 4</option> 
<option value="5">Opt 5</option> 
</select> 

也許有更好的方法來做到這一點?

回答

相關問題