javascript - react 范围输入 IE11 onChange 或 onInput 解决方法

标签 javascript html reactjs

IE11 uses onChange instead of onInput对于 <input type='range'>元素。

react does not call either of these在 IE11 中。

onInput适用于 FF、Chrome 和 Edge,所以没问题。

沿着兔子洞向下会引出 herehere , 建议使用 onMouseUponClick ,但我也没有得到这个工作。

我试过各种监听器组合都无济于事。我什至试过this (当然,这也不起作用)。有人对此有解决方法吗?

最佳答案

经过一番挖掘,我选择了 react-range因为它轻巧、简单且有效。

render() 在其 source 中显示它是如何做到的:

render: function() {
    var props = _extends({}, this.props, {
      defaultValue: this.props.value,
      onClick: this.onRangeClick,
      onKeyDown: this.onRangeKeyDown,
      onMouseMove: this.onRangeChange,
      onChange: function() {},
      ref: this.setRangeRef
    });
    delete props.value;
    return React.createElement(
      'input',
      props
    );
  }

更新

看来这将在 React 16 中得到修复:https://github.com/facebook/react/issues/554#issuecomment-271579096

If you look at the history above, you will see that the issue was closed by #5746. If you open this PR, you will see that its milestone is set to 16.

So the fix will be in 16, and we can’t put it in 15.x because it introduces a breaking change in behavior.

I don’t know if it’s possible to backport it to 15.x. @jquense and @nhunzaker would likely be able to answer this.

关于javascript - react 范围输入 IE11 onChange 或 onInput 解决方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39047171/

相关文章:

javascript - 无法导入html中的js文件

javascript 正则表达式和替换

php - 如何将 mysql 数据提取到带有垂直标题的 html 表中?

reactjs - 用 Jest mock snackbar

javascript - 舍入 humanize-duration 格式值中的最后一个值 (React)

javascript - 读取JSON文件,更新值并保存修改

html - 制作一个按钮以在 div 中水平滚动

python - 在 HTML 中显示 Python 值

javascript - 你好,世界不使用 React js 中的功能组件进行打印

javascript动态添加值到数组