日期:2014-05-16  浏览次数:20364 次

为什么这段JS的代码不能给文本框赋值呢?只有“标规”按钮有用。谢谢!
<script type="text/javascript"> 
function SetText(messageindex){
if (messageindex = 0){
document.getElementById("txtId1").value = "109.2";
document.getElementById("txtId2").value = "78.7";
}
else if (messageindex = 1){
document.getElementById("txtId1").value = "119.4";
document.getElementById("txtId2").value = "88.9";
}
else if (messageindex = 2){
document.getElementById("txtId1").value = "";
document.getElementById("txtId2").value = "";
}
else if (messageindex = 3){
document.getElementById("txtId3").value = "";
document.getElementById("txtId4").value = "";
}
else if (messageindex = 4){
document.getElementById("txtId1").value = "";
document.getElementById("txtId2").value = "";
document.getElementById("txtId3").value = "";
document.getElementById("txtId4").value = "";
}
}
</script>
</head>
<body>
<form name="jisuanqi" id="jsq" action="" method="get">
  <p> 本纸长:
  <input type="text" size="29" name="bzc" id="txtId1" />
  </p>
  <p> 本纸高:
  <input type="text" size="29" name="bzg" id="txtId2" />
  </p>
  <p>目标纸长:
  <input type="text" size="29" name="mbzc" id="txtId3" />
  </p>
  <p>目标纸高:
  <input type="text" size="29" name="mbzg" id="txtId4" />
  </p>
  <p>
  <input type="button" value="标规" onclick="SetText(0)" />
  <input type="button" value="大规" onclick="SetText(1)" />
  <input type="button" value="清空本纸" onclick="SetText(2)" />
  <input type="button" value="清空目标纸" onclick="SetText(3)" />
  <input type="button" value="全清" onclick="SetText(4)" />
  </p>
  反馈信息:
  <p>
  <label for="textarea"></label>
  <textarea name="fkxx" id="textarea" cols="30" rows="8"></textarea>
  </p>
  <p>
  <input type="button" class="btn" value="计算" onClick="calc()"/>
  </p>
</form>

------解决方案--------------------
HTML code

<script type="text/javascript">  
function SetText(messageindex){
if (messageindex == 0){
document.getElementById("txtId1").value = "109.2";
document.getElementById("txtId2").value = "78.7";
}
else if (messageindex == 1){
document.getElementById("txtId1").value = "119.4";
document.getElementById("txtId2").value = "88.9";
}
else if (messageindex == 2){
document.getElementById("txtId1").value = "";
document.getElementById("txtId2").value = "";
}
else if (messageindex == 3){
document.getElementById("txtId3").value = "";
document.getElementById("txtId4").value = "";
}
else if (messageindex == 4){
docum