使多个链接可见javascript

时间:2012-05-02 09:47:32

标签: javascript

一次可以看到多个链接吗?我的意思是在我的以下代码中,当我在文本字段中输入project并按提交按钮时,abc.htm链接变为可见。现在,当我在文本字段中输入project并按下提交按钮abc.htmxyz.htmcold.htm链接可见时,我希望这样。如果在文本字段中写下,则相同。

    <html>
    <head>
    <script Language="JavaScript">
    <!--
    function Blank_TextField_Validator() {
    // Check the value of the element named text_name from the form named text_form
    if (text_form.text_name.value == "") {
    // If null display and alert box
    alert("Please fill in the text field.");
    // Place the cursor on the field for revision
    text_form.text_name.focus();
    // return false to stop further processing
    return (false);
    }
    // If text_name is not null continue processing
   if (text_form.text_name.value == "project")
   document.getElementById('project_link').style.display = 'block';
   else if (text_form.text_name.value == "under")
   document.getElementById('construction_link').style.display = 'block';
   else
   alert("Invalid keyword!");
   return (false);
   }
   -->
   </script>
   </head>
   <body>
   <form name="text_form" method="get" action="#" 
    onsubmit="return Blank_TextField_Validator()">
    <a id='project_link' href='abc.htm' style='display: none;'>project</a>
     <a id='construction_link' href='New Text Document (3).htm' style='display:     none;'>construction</a>
     <input type="text" name="text_name" >
     <input type="submit" value="Submit">
    </form>
     </body>
     </html>

这就是我的尝试:

if (text_form.text_name.value == "project") 
    document.getElementById('project_link').style.display = 'block'; 
    document.getElementById('project_link_1').style.display = 'block'; 

<form name="text_form" method="get" action="#" onsubmit="return Blank_TextField_Validator()">
    <a id='project_link' href='abc.htm' style='display: none;'>project</a> 
    <a id='project_link_1' href='xyz.htm' style='display: none;'>projects</a> 
    <a id='construction_link' href='New Text Document (3).htm' style='display: none;'>construction</a>

1 个答案:

答案 0 :(得分:0)

更改

if (text_form.text_name.value == "project") 
    document.getElementById('project_link').style.display = 'block'; 
    document.getElementById('project_link_1').style.display = 'block'; 

if (text_form.text_name.value == "project") {
    document.getElementById('project_link').style.display = 'block'; 
    document.getElementById('project_link_1').style.display = 'block'; 
}
不过,我真的同意评论员对原始问题的看法:在发布有关它的问题之前,你应该学习JavaScript。你需要知道你实际上在做什么才能成功。