0

一度に複数のリンクを表示できますか? 次のコード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>
4

1 に答える 1

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 を学ぶべきです。成功するためには、実際に何をしているのかを知る必要があります。

于 2012-05-02T11:32:26.650 に答える