简体   繁体   中英

How do I access a variable from my markup page?

This is going to sound pretty basic but I have to ask anyways.I have a jQuery range slider, I have labels that show what step the slider handle is at. So I added this variable

var myData = $("slider-range").slider("option", "min");

In my codebehind page I'm trying to access that variable and I can't figure it out.

The code for the slider is,

$(function () {

    $("#slider-range-Monday").slider({

        create: function (e, ui) {
            var c = $(this).children('.ui-slider-handle')
            $(c[0]).append('<a class="ui-slider-label">0</a>');
            $(c[1]).append('<a class="ui-slider-label">24</a>');
        },

              range: true,

              min: 0,

              max: 24,

              values: [0, 24],

              animate: 'slow',



              slide: function (event, ui) {
                  $('.ui-slider-label', this)[0].innerHTML = ui.values[0];
                  $('.ui-slider-label', this)[1].innerHTML = ui.values[1];

                  $("#amount").val("$" + ui.values[0] + " - $" + ui.values[1]);

              }

          });

          $("#amount").val("$" + $("#slider-range").slider("values", 0) +

            " - $" + $("#slider-range").slider("values", 1));

          var myData = $("slider-range").slider("option", "min");

});

I need to be able to access the sliders values and I don't know how. I thought about adding a hidden label to the sliders labels and I don't know how to do that later. If this has been asked before please point me in the right direction.

Thanks

You can add a hidden field

   <asp:HiddenField ID="hiddenField" runat="server" />

Set its value like

$(document).ready(function() {
    $("#<%=hiddenField.ClientID%>").val(myData )
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM