Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
html5中的if-then语句_Html_If Statement - Fatal编程技术网

html5中的if-then语句

html5中的if-then语句,html,if-statement,Html,If Statement,我正在创建一个网站。我有一个页面,我有一个下拉列表,我想让它,当用户选择“其他”选项时,一个文本框出现。我该怎么做 这是我的密码: <!DOCTYPE html> <html> <html lang = "en"> <body> <p id="demo"></p> <h1>What would you like it to say?</h1> <p>Commmon Re

我正在创建一个网站。我有一个页面,我有一个下拉列表,我想让它,当用户选择“其他”选项时,一个文本框出现。我该怎么做

这是我的密码:

 <!DOCTYPE html>
 <html>
 <html lang = "en">
 <body>

 <p id="demo"></p>

 <h1>What would you like it to say?</h1>

 <p>Commmon Requests:</p>

 <form action="input" action="random.html" method="get">
 <select name="requests">
 <option value="blank"> </option>
 <option value="good morning sir">Good Morning Sir</option>
 <option value="good morning madam">Good Morning Madam</option>
 <option value="other">Other</option>   
 <input type="submit" value="Submit">
 </select>
 </form>

 <br><br><textarea rows="3" cols="30">
 Write a request here if you would like to hear it.
 </textarea>

 </body>
 </html>

你希望它说什么? Commmon请求:

早上好,先生 早上好,女士 其他

如果你想听的话,在这里写一个请求。
使用一个函数将“onchange”事件附加到您的select元素,该函数检查哪个选项是所选值,如果是“Other”选项,则将隐藏的文本框从隐藏更改为可见。示例如下:

<form action="input" action="random.html" method="get">
    <select id="requestDropDown" name="requests" onchange="checkOption()">
        ....
    </select>
    <input type="text" id="otherBox" style="visibility:hidden;"/>
</form>
它简单明了。

使用一个函数将“onchange”事件附加到您的select元素,该函数检查哪个选项是所选值,如果是“Other”选项,则将隐藏的文本框从隐藏更改为可见。示例如下:

<form action="input" action="random.html" method="get">
    <select id="requestDropDown" name="requests" onchange="checkOption()">
        ....
    </select>
    <input type="text" id="otherBox" style="visibility:hidden;"/>
</form>

它简单明了。

使用Javascript实现这一点相当简单。不要将HTML用于构建网站内容以外的任何内容

<form method="post" action="">
<select name="requests" onchange="openbox(this);">
    ...
    <option value="other">Other</option>
</select>
</form>
...
<textarea rows="3" cols="30" hidden>
Write a request here if you would like to hear it.
</textarea>
编辑:当你说文本框时,我出于某种原因想到了一个警告。
W3C学校参考:

使用Javascript实现这一点相当简单。不要将HTML用于构建网站内容以外的任何内容

<form method="post" action="">
<select name="requests" onchange="openbox(this);">
    ...
    <option value="other">Other</option>
</select>
</form>
...
<textarea rows="3" cols="30" hidden>
Write a request here if you would like to hear it.
</textarea>
编辑:当你说文本框时,我出于某种原因想到了一个警告。
W3C学校参考资料:

以下作品:

<!DOCTYPE html>
 <html lang = "en">
 <body>

        <p id="demo"></p>

        <h1>What would you like it to say?</h1>

        <p>Common Requests:</p>

        <form action="input" action="random.html" method="get">

        <select name="requests" onchange="checkIfOther();" id="dropDown1">

        <option value="blank"> </option>
        <option value="good morning sir">Good Morning Sir</option>
        <option value="good morning madam">Good Morning Madam</option>
        <option value="other">Other</option>

        </select>

        <input type="submit" value="Submit"/>
        </form>

        <div id="other" style="display:none">

            <label>Other(Please explain):</label><input type="text" id="otherText"/>


        </div>

        <br><br><textarea rows="3" cols="30">
        Write a request here if you would like to hear it.
        </textarea>

 </body>
 </html>

<script>

    function checkIfOther(){

        a = document.getElementById("dropDown1");        

        if(a.value == "other")           

            document.getElementById("other").setAttribute("style","display:inline");

        else

            document.getElementById("other").setAttribute("style","display:none");


        }

</script>

你希望它说什么? 共同要求:

早上好,先生 早上好,女士 其他 其他(请解释):

如果你想听的话,在这里写一个请求。 函数checkIfOther(){ a=document.getElementById(“下拉列表1”); 如果(a.值=“其他”) document.getElementById(“其他”).setAttribute(“样式”,“显示:内联”); 其他的 document.getElementById(“其他”).setAttribute(“样式”,“显示:无”); }
以下功能也适用:

<!DOCTYPE html>
 <html lang = "en">
 <body>

        <p id="demo"></p>

        <h1>What would you like it to say?</h1>

        <p>Common Requests:</p>

        <form action="input" action="random.html" method="get">

        <select name="requests" onchange="checkIfOther();" id="dropDown1">

        <option value="blank"> </option>
        <option value="good morning sir">Good Morning Sir</option>
        <option value="good morning madam">Good Morning Madam</option>
        <option value="other">Other</option>

        </select>

        <input type="submit" value="Submit"/>
        </form>

        <div id="other" style="display:none">

            <label>Other(Please explain):</label><input type="text" id="otherText"/>


        </div>

        <br><br><textarea rows="3" cols="30">
        Write a request here if you would like to hear it.
        </textarea>

 </body>
 </html>

<script>

    function checkIfOther(){

        a = document.getElementById("dropDown1");        

        if(a.value == "other")           

            document.getElementById("other").setAttribute("style","display:inline");

        else

            document.getElementById("other").setAttribute("style","display:none");


        }

</script>

你希望它说什么? 共同要求:

早上好,先生 早上好,女士 其他 其他(请解释):

如果你想听的话,在这里写一个请求。 函数checkIfOther(){ a=document.getElementById(“下拉列表1”); 如果(a.值=“其他”) document.getElementById(“其他”).setAttribute(“样式”,“显示:内联”); 其他的 document.getElementById(“其他”).setAttribute(“样式”,“显示:无”); }

html

html


您应该将“提交”按钮保留在下拉列表之外。如果我的答案与您需要的完全一致,则将其作为答案接受。您应该将“提交”按钮保留在下拉列表之外。如果我的答案与您需要的完全一致,则将其作为答案接受。
function check(that) {
        if (that.value === "other") {
            var textBox = document.createElement('input');
            textBox.setAttribute("type", "text");
            textBox.setAttribute("id", "newTextBox");
            document.getElementById('form1').appendChild(textBox);
        }

        else {
            var box = document.getElementById('newTextBox');
            if (box)
                box.parentNode.removeChild(box);
        }
    }