将单选按钮的脚本更改为常规按钮

时间:2014-03-06 21:56:30

标签: javascript jquery html button radio-button

所以我有一个我一直在使用的脚本,它可以很好地用于我的目的,但它是用单选按钮构建的,我被要求用它做另一个项目,但是我的老板想按钮来现在是常规的非单选按钮。

这是我到目前为止使用的代码。将单选按钮代码更改为常规按钮代码要比我想象的要困难得多!非常感谢任何帮助,谢谢!

<!DOCTYPE html>
<html>
<head>
<style>
#TFholder{
   background-image:url('truefalse.png');
   height:84px;
   width:576px;
}

button{
    height:84px; 
    width:280px; 
    color:white; 
    background-color:black;      
    margin-top:50px; 
    text-align:center; 
    line-height:10px;
    border:none;
    outline:none;}

button a{
    display:block;
    color:white;
    text-decoration:none;
    padding:20px 40px;}
</style>  

</head>
<body>

<script type="text/javascript">
function onCheck() {
if (document.getElementById('check1').checked) {
    document.getElementById('truebox').style.display = 'block';

    }
else document.getElementById('falsebox').style.display = 'block';

    }
</script>
<input type="radio" onclick="javascript:onCheck();" name="check" id="check1"><br> 
<input type="radio" onclick="javascript:onCheck();" name="check" id="check2"><br>
<div id="TFholder">
  <div id="truebox" style="display:none">
    <button type="button">CONTINUE!!!</a></div>
  </div>

  <div id="falsebox" style="display:none">
     <button type="button">SECOND BUTTON!!!</a></div>
  </div>
</div>

</body>
</html>

1 个答案:

答案 0 :(得分:1)

将HTML部分更改为:

<input id="Button1" type="button" value="button" onclick="javascript:b1();"/><br />
<br />
<input id="Button2" type="button" value="button" onclick="javascript:b2();"/><br>

将脚本部分更改为:

<script type="text/javascript">
    function b1() {
        document.getElementById('truebox').style.display = 'block';
    }

    function b2() {
        document.getElementById('falsebox').style.display = 'block';
    }
</script>