简体   繁体   English

如何使用Javascript滑块的值

[英]How to use the value of a Javascript slider

I am using a JavaScript slider as a plugin in a form, but this is my first working with JS, how do I get the value of the slider to show elsewhere on my page in order for me to use this value as a variable in my php page in order for me to write this to a MySQL database later. 我正在使用JavaScript滑块作为表单中的插件,但这是我第一次使用JS,如何获取滑块的值以显示在页面的其他位置,以便我将此值用作变量。 php页面,以便我稍后将其写入MySQL数据库。

Following is a snippet of the code, the creator says you call the value by using function slide(ui, value) , but I have tried and failed... How do I get this value as a php variable such as $mySliderValue : 以下是代码片段,创建者说您通过使用function slide(ui, value)调用了值,但是我尝试并失败了...我如何以php变量(例如$mySliderValue获取该值:

<script>
    var slider = $('#slider').CircularSlider({
        radius: 154,
        innerCircleRatio: '0.59',
        handleDist: 96,
        min: 100,
        max: 3000,
        value: 500,
        clockwise: true,
        labelSuffix: "",
        labelPrefix: "R ",
        shape: "Half Circle Left",
        touch: true,
        animate: true,
        animateDuration : 360,
        selectable: false,
        slide: function(ui, value) {},
        onSlideEnd: function(ui, value) {},
        formLabel: undefined
    });
</script>

If you are using this slider in a form, then i believe that you have to make your own onSlideEnd function that maybe updates a hidden input field with the new slider value: 如果您以某种形式使用此滑块,那么我认为您必须创建自己的onSlideEnd函数,该函数可能会使用新的滑块值更新隐藏的输入字段:

var slider = $('#slider').CircularSlider({
    ...
    onSlideEnd: function(ui, value) { $('#myHiddenInput').val(value); },
    ...
});

and then ofcourse remember to make the input: 然后当然记得输入以下内容:

<input type="hidden" id="myHiddenInput" name="slider_value" />

I believe the JavaScript value will be on the client side and you would need to preform an http POST request to get it back to your server-side PHP. 我相信JavaScript值将在客户端,您需要执行一个HTTP POST请求才能将其返回到服务器端PHP。 Many times, we do this using an asynchronous AJAX request. 很多时候,我们使用异步AJAX请求来执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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