【问题标题】:Can someone spot the error in my code? My html is not adjusting to the changed values有人可以在我的代码中发现错误吗?我的 html 没有适应更改的值
【发布时间】:2019-09-18 00:17:35
【问题描述】:

由于某种原因,我的 html 没有适应我输入的 JavaScript。标签没问题,但由于某种原因,我的网站对输入框中的更改没有反应。 * 请帮我找出问题所在! * 下面给出了转换器代码以及 HTML。

JAVASCRIPT

let VSWRout = document.getElementById('VSWRout');
let Mismatchout2 = document.getElementById('MisMatchOut2');
let RLin = document.getElementById('RLin1');

/**
 * @return {number}
 */
function RLintoVSWRout(){
    return Math.round((Math.pow(10,((parseFloat(RLin.value))/20)) + 1) / (Math.pow(10,((parseFloat(RLin.value))/20)) - 1) * 100) /100;
}
/**
 * @return {number}
 */
function RLintoMismatchout2(){
    return Math.round((-10 * Math.log10(Math.pow((Math.pow(10,(-parseFloat(RLin.value)/ 20))), 2)))*100) /100;
}
function RLconverter(){
    VSWRout.html = '<td id=VSWRout>' + RLintoVSWRout() + '</td>';
    Mismatchout2.html = '<td id=MisMatchOut2>' + RLintoMismatchout2() + '</td>'
}

RLin.addEventListener('change', RLconverter, false);

HTML

 <section>
      <!---VSWR, RL(dB), MismatchLoss(dB) -->
      <table id="VSWR,RL,MismatchLoss">
          <tr>
            <td>VSWR</td>
            <td>RL(dB)</td>
            <td>Mismatch Loss(dB)</td>
          </tr>

          <tr>
            <td><label for="VSWR"></label><input type="number" id="VSWR" min="1" /> </td>
            <td>later</td>
            <td>later</td>
          </tr>

          <tr>
            <td id="VSWRout"></td>
            <td><label for="RLin1"></label><input type="number" id="RLin1" min="0" /> </td>
            <td id="MisMatchOut2"></td>
          </tr>

      </table>      
    </section>

我目前专注于最后一行。

【问题讨论】:

  • 确保清除缓存。
  • 如果您有解决方案,请添加答案;不要把它放在问题中。

标签: javascript html input error-handling output


【解决方案1】:

RLconverter 函数更改为使用innerHTML 而不是html:

不正确:

function RLconverter(){
    VSWRout.html = '<td id=VSWRout>' + RLintoVSWRout() + '</td>';
    Mismatchout2.html = '<td id=MisMatchOut2>' + RLintoMismatchout2() + '</td>'
}

正确:

function RLconverter(){
    VSWRout.innerHTML = '<td id=VSWRout>' + RLintoVSWRout() + '</td>';
    Mismatchout2.innerHTML = '<td id=MisMatchOut2>' + RLintoMismatchout2() + '</td>'
}

【讨论】:

    猜你喜欢
    • 2020-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多