如何检索和显示滑块范围值? [英] How can I retrieve and display slider range value?

查看:28
本文介绍了如何检索和显示滑块范围值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从输入范围中检索和显示滑块值?

How can I retrieve and display the slider value from the input range?

我正在使用 Meteor 并且更喜欢 javascript 代码.

I am using Meteor and prefer javascript code.

  <input id="slider" type="range" min="50" max="100" step="10" oninput="sliderChange(this.value)">

  <output id="sliderVal"> </output>

javascript;

javascript;

function sliderChange(val) {
document.getElementById('sliderVal').innerHTML = val;
}

推荐答案

引用后http://www.w3schools.com/jsref/event_oninput.asp看来您可以根据 oninput 的更改事件执行方法.

After referencing http://www.w3schools.com/jsref/event_oninput.asp it seems you can execute a method upon the change event of oninput.

以下代码检索并显示页面上的数字.

The following code retrieves and displays the numbers on the page.

<template name="myTemplate>
 <input id="slider" type="range" min="50" max="100" step="10"  value="50">
 <output id="output"></output>
</template>

client.js

Template.myTemplate.rendered = function(){
document.getElementById("slider").oninput = function() {
    myFunction()
};
}

function myFunction() {
   var val = document.getElementById("slider").value //gets the oninput value
   document.getElementById('output').innerHTML = val //displays this value to the html page
   console.log(val)
}

流星方式:此外,您可以使用 change eventType 并按照您的意愿进行映射.这在输入更改状态时有效.

THE METEOR WAY: Additionally, you may use the change eventType and map it how you want. This works when an input changes state.

Template.yourTemplate.events({
  'change input[type=range]': function(event){
     var sliderValue = event.currentTarget.value
     Session.set('sliderValueIs', sliderValue)
     //then you can get this session and return it in a helper to display on your page
  }
})

这篇关于如何检索和显示滑块范围值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆