首页 > 解决方案 > 刷新时如何使用 select onchange 保留值?

问题描述

我可以切换输出值,但是当我点击刷新时,该值被重置。我需要留下的价值。

function dateFunction() {
  var x = document.getElementById("ClaimContact").value;
  if (x == 0){				
    document.getElementById("answer").value = "Yes";	
  }
  if (x != 0){
    document.getElementById("answer").value = "No";
  }
}
<table width="100%" cellspacing="0" cellpadding="0" border="1" rules="rows" class="QuestionTable">
  <tr>
    <td #questionstyle# width="10%">Contact?</td>
    <td>
      <select name="ClaimContact" id="ClaimContact" onchange="dateFunction()">
        <option value=""></option>
        <option value="0">Y</option>
        <option value="1">N</option>
      </select>
    </td>	
    <td #answerstyle# align="right">
      <input type="text" id="answer" readonly style="border: none; text-align: right;">
    </td>
  </tr>
</table>

标签: javascriptcsshtmlwebpage

解决方案


您是否将值存储在任何地方?如果没有将所选值存储在本地存储中,它将起作用


推荐阅读