输入完成时显示图像的多个IF语句

时间:2014-07-21 16:35:08

标签: javascript if-statement

我似乎无法获得多个IF语句来处理我的脚本。我想要一个图像出现在三个输入字段有文本时,而不是只有一个或两个有文本。任何帮助将非常感激。

HTML:

<form method="post" action="email-case-study-checker.php" onsubmit="return submitToHighslide(this)">

       Full Name  <span class="required">*</span><br />
        <input name="your_name" type="text" id="name" title="Enter your full name" size="36" maxlength="50"><br /><br />

        Company  <span class="required">*</span><br />
        <input name="your_company" type="text" id="company" title="Enter your company name" size="36" maxlength="50"><br /><br />

        Email Address  <span class="required">*</span><br />
        <input name="your_email" type="text" id="email" title="Enter your email address" size="36" maxlength="50"><br /><br />

 <div id="hiddenpdf"> <a href="pdfs/Southend-On-Sea-Council-Case-Study.pdf"> Right click and save link as to download pdf</a></div>

使用Javascript:

<script>
function hiddenpdf() 
{
    if(document.getElementById('name').value == "") {
    if(document.getElementById('company').value == "") {
    if(document.getElementById('email').value == "");}

    {
            document.getElementById('hiddenpdf').style.display = 'none';

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

}

</script>

1 个答案:

答案 0 :(得分:0)

if (document.getElementById('name').value != "" && document.getElementById('company').value != "" && document.getElementById('email').value != ""){
   document.getElementById('hiddenpdf').style.display = 'block'; 
}else{
    document.getElementById('hiddenpdf').style.display = 'none';
}

希望这有帮助。

您的代码中存在语法错误。以上解决方案检查&#34;和&#34;逻辑,只会执行&#39;阻止&#39;声明如果满足所有三个条件,否则它将转移到else语句。