“ oninput事件”在WordPress帖子编辑器中不起作用

时间:2018-12-25 15:43:39

标签: javascript wordpress html5

我正在执行一些运行时计算。计算是关于在一个文本框字段中插入一个值,它将在另一个文本框字段中显示输出。一个简单的HTML网页可以很好地工作。但是,当我在WordPress帖子/页面编辑器中粘贴相同的HTML5和Javascript代码时。它不显示任何输出。我需要它可以与Wordpress页面或帖子编辑器一起使用。

<script>
    function accConverter(source,valNum) {
        valNum = parseFloat(valNum);
        var inputms2  = document.getElementById("inputms2");
        var inputkms2 = document.getElementById("inputkms2");
        if (source == "inputms2") {
            inputkms2.value = (valNum/1000);
        }
        if (source == "inputkms2") {
            inputms2.value = (valNum * 1609.344);
        }
    }
</script>
<html>
    <div class = "input-unit-2 clearfix">
        <label class = "unit-label">meters per square second</label>
        <input id = "inputms2" class = "input-unit-box" type = "number"
        oninput = "accConverter(this.id, this.value)">
        <div class = "after-label">m/s2</div>
    </div>
    <div class = "input-unit-2 clearfix">
        <label class = "unit-label">kilometers per square second</label>
        <input id = "inputkms2" class = "input-unit-box" type = "number"
        oninput = "accConverter(this.id, this.value)">
        <div class = "after-label">km/s2</div>
    </div>
</html>

0 个答案:

没有答案