我在移动调查应用程序中使用JQuery UI滑块。如果单击标签或将手柄移动到标签,我可以正确捕获滑块值。我的问题是,如果用户没有点击标签/移动滑块。我想记录滑块的初始值。这是滑块所在的html:
<div class="well-lg">
<b>@Html.DisplayFor(model => model.QuestionsText)</b><div id="mySlideOutput"></div>
<br />
<div id="mySlideOutput"></div> // testing output of slider value
<br />
@*Include ID of EvaluationQuestion in ID of slider*@
<div id="slider-@(Model.ID)"></div>
@Html.Hidden("QR-" + @Model.ID)
</div>
这是Jquery代码:
<script>
var items = ['Very Exceptional Results', 'Above Standard', 'Standard', 'Results Not Acceptable', 'Less Than Standard', 'N/A'];
@*var sliderDefault = $("#slider-@(Model.ID)"),
initialValue = 1;*@
// commented out code that was used to make sure the value is being populated at certain states
//NOTE: Needs to be changed to populate slider item labels from database.
$("#slider-@(Model.ID)").slider({
value: initialValue,
min: 1,
max: 6,
//step: 1,
slide: function (event, ui) {
$("#QR-@(Model.ID)").val(ui.value);
$('#mySlideOutput').html('ui-value = ' + ui.value);
},
@*stop: function(event, ui) {
$("#QR-@(Model.ID)").val(ui.value);
//alert(ui.value);
},*@
@*start: function(event, ui) {
$("#QR-@(Model.ID)").val(ui.value);
alert(ui.value);
}*@
});
$("#slider-@(Model.ID)").slider("pips", { rest: "label", labels: items });
如果滑块没有移动到另一个选项,我希望初始值填充数据库。有什么建议?我很感激帮助。
答案 0 :(得分:0)
$("#slider-@(Model.ID)").slider("value");
这只会在调用时返回滑块的值...是否要在运行时调用此函数,或者只是在页面卸载之前调用此函数。