0

我用 cal() 创建了一个表单,但我无法让它与无线电输入一起工作。它与选择和选项一起使用,但现在没有采用该值。

这里的代码

<script> 
function cal()
 { 
  var pl=document.form1.template.value; 
  var resultat=pl; 
  document.form1.tresultat.value=resultat; 
  document.formfin.tresultatfin.value = calfin(); 
  } 
</script> 

<form name="form1">
  <label for="Template">Option 1 : Template</label>
  <ul>
  <li id="template"><label for="logo+texte">Logo et texte</label> 
 <input type="radio" id="test" name="template" value="500" onclick="cal()"></li>
 <li><label for="base">Base</label> 
 <input type="radio" id="test" name="template" value="800" onclick="cal()"></li>
 <li><label for="perso">Sur-Mesure</label> 
 <input type="radio" id="test" name="template" value="2900" onclick="cal()"></li></ul>
  <input type="text" value="0" name="tresultat">
 </form>

任何想法在选择时获取文本输入中的值?谢谢

4

1 回答 1

0

单选按钮很奇怪,因为有一个单独的元素列表,而不仅仅是一个。最简单的做法是将元素本身作为参数传递:

function cal( button )
 { 
  var pl = button.value; 
  var resultat=pl; 
  document.form1.tresultat.value=resultat; 
  document.formfin.tresultatfin.value = calfin(); 
 }

然后更改单选按钮:

 <input type="radio" id="test" name="template" value="800" onclick="cal( this )"></li>

传递this给函数。

于 2014-01-23T16:08:10.623 回答