如何让IF ELSE返回图像?

时间:2016-02-20 15:42:43

标签: javascript if-statement

我有这个if if脚本返回"正确"或"不正确"

如何让它返回图像而不是文本?

我想使用的图片是: 正确:http://leowestonvfx.com/wp-content/uploads/2016/02/rock-hand.png 不正确:http://leowestonvfx.com/wp-content/uploads/2016/02/thumbs-down.png

What is 1 + 1?<br>

Answer:&nbsp;<input type="text" length="3" id="ANSWER1A">
<input type="button" value="Enter" onclick="Q1A()">

<script language="javascript">
    function Q1A()
    {
        var A = document.getElementById("ANSWER1A").value;
        var A;
        if (A == '2') {
        R = "CORRECT";
    } else {
        R = "INCORRECT";
    } 
document.getElementById("RETURN1A").innerHTML = R;
    }
</script>

<p id="RETURN1A">

1 个答案:

答案 0 :(得分:1)

What is 1 + 1?<br>

Answer:&nbsp;<input type="text" length="3" id="ANSWER1A">
<input type="button" value="Enter" onclick="Q1A()">

<script language="javascript">
    function Q1A()
    {
        var A = document.getElementById("ANSWER1A").value;
        var A;
        if (A == '2') {
        R = "http://leowestonvfx.com/wp-content/uploads/2016/02/rock-hand.png";
    } else {
        R = "http://leowestonvfx.com/wp-content/uploads/2016/02/thumbs-down.png";
    } 
document.getElementById("RETURN1A").src = R;
    }
</script>

<img id="RETURN1A">

&#13;
&#13;
What is 1 + 1?<br>

Answer:&nbsp;<input type="text" length="3" id="ANSWER1A">
<input type="button" value="Enter" onclick="Q1A()">

<script language="javascript">
    function Q1A()
    {
        var A = document.getElementById("ANSWER1A").value;
        var A;
        if (A == '2') {
        R = "http://leowestonvfx.com/wp-content/uploads/2016/02/rock-hand.png";
    } else {
        R = "http://leowestonvfx.com/wp-content/uploads/2016/02/thumbs-down.png";
    } 
document.getElementById("RETURN1A").src = R;
    }
</script>

<img id="RETURN1A">
&#13;
&#13;
&#13;