2012-05-02 28 views
0

有沒有一種方法,而不是打開新頁面上的鏈接,下面的代碼可以使鏈接在同一頁面上可見?例如,如果我在文本字段中輸入「project」,然後按提交按鈕,則頁面上將顯示鏈接,即「project.htm」。如果我在文本框中寫下「下」並按提交按鈕,則underconstruction.htm鏈接變得可見。文本框使鏈接可見使用if else語句,javascript

<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") 
       window.open('project.htm'); 
      else if (text_form.text_name.value == "under") 
       window.open('underconstruction.htm'); 
      else 
       alert("Invalid keyword!"); 
      return (true); 
     } 
    --> 
    </script> 

回答

0

不知道這是不是一個技巧性的問題..你不能這樣做嗎?

腳本

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); 

標記

<a id='project_link' href='project.htm' style='display: none;'>project</a> 
<a id='construction_link' href='underconstruction.htm' style='display: none;'>construction</a> 
+0

可以請你寫出完整的代碼,因爲我沒有得到在哪裏添加的標記部分。 –

+0

@JavariaShah這只是與你的標記的其餘部分(無論哪裏**

**是)。 – McGarnagle

+0

你的意思是?它不在這裏工作。 <形式名稱= 「text_form」 方法= 「GET」 行動= 「#」 的onsubmit = 「返回Blank_TextField_Validator()」> <輸入類型=「提交」值=「提交」> –