1

I am trying to update the value of Telerik MVC slider from a text field which is updated from a javascript. Here is the Telerik script:

 <input value="" id="PSlice" name="PSlice" />
<%= Html.Telerik().Slider<int>()
        .Name("SliceSlider")
        .HtmlAttributes(new { style = "color: white" })
        .TickPlacement(SliderTickPlacement.None)
        .Value((int[])$('#PSlice').val())
        .Max(100)
        .Min(0)
        .ClientEvents(events => events
            .OnLoad("onLoadSlider")
            .OnChange("onChangeSlider")
            .OnSlide("onSlideSlider"))
        %><br />

I get the following error:

Unexpected character '$'
 .Value((int[])$('#PSlice').val())

I put the value of the text field from:

function Playimages() {
  i = (i < sl - 1) ? (i + 1) : 0;
  $('#Image1').attr('src', images[i].src);
  $('#PSlice').val(i);
}

Would appreciate your suggestions.

4

1 回答 1

0

Value不能是表达式。PSlice因为这基本上都是在客户端完成的,所以当使用一些 JavaScript更新滑块时,您需要更新滑块。

<input type="text" value="" id="PSlice" name="PSlice" />
<%= Html.Telerik().Slider<int>()
        .Name("SliceSlider")
        .HtmlAttributes(new { style = "color: white" })
        .TickPlacement(SliderTickPlacement.None)
        .Max(100)
        .Min(0)
        .ClientEvents(events => events
            .OnLoad("onLoadSlider")
            .OnChange("onChangeSlider")
            .OnSlide("onSlideSlider"))
        %>
<script type="text/javascript">
// some wireup on load...
$(function() {
   var sliceSlider = $('#SliceSlider').data('tSlider'); // get slider object

   // set initial slider 
   $('#PSlice').on('change', function() {
     sliceSlider.value($(this).val());
   });
});
</script>
于 2012-08-31T04:58:32.923 回答