Javascript代码无效 [英] Javascript code not working

查看:78
本文介绍了Javascript代码无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过此代码实现以下功能。如果我输入y,将显示图像。但不仅是'y',当我把任何字符放在图像上时。如何解决这个问题?





I am trying to achieve the following thing by this code. That if i enter "y" the image will be shown. But not only 'y' when i put any character the image is shown. How to solve this?


<html>
    <head>
        <title>Emogic</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    </head>
    <body>
    <img id="img" src="">
<input type="text" />
<button>click me!</button>


    <script>
    $("button").click(function() {
    if($("input").val() == 'Y' || 'y'){
        $("#img").attr("src", "airplane105.png");
    }
});

    </script>
    </body>
</html>

推荐答案

(< span class =code-string> button)。click( function ( ){
if
("button").click(function() { if(


< span class =code-string> input)。val()== ' Y' || ' y'){
("input").val() == 'Y' || 'y'){


#img)。attr( src airplane105.png);
}
});

< / script >
< / body >
< / html >
("#img").attr("src", "airplane105.png"); } }); </script> </body> </html>


这篇关于Javascript代码无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆