按钮单击以显示下拉列表 [英] Button click to show a dropdown
本文介绍了按钮单击以显示下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试执行此操作,将显示提交类型常规按钮。点击后,
显示一个下拉列表,选择一个值后,另一个下拉列表显示然后提交。
怎么做我这样做了吗?
这是我开始的事情...
<!DOCTYPE html>
< html>
< body>
< p>单击按钮以触发一个函数,该函数将在id为demo的p元素中输出Hello World。< / p>
< button onclick =myFunction()>点击我< / button>
< p id =demo>< / p>
< script>
函数myFunction(){
document.getElementById(demo)。innerHTML =< select>;
}
< / script>
< / body>
< / html>
解决方案
< 按钮 onclick = 返回myFunction() > 点击我< / button >
< p id = demo > < / p >
< pid = demob > < / p >
< script >
function myFunction(){
//追加整个html for a选择
document.getElementById(demo)。innerHTML + =< 选择 < span class =code-keyword>> < 选项 value =' 1' > 一个< / option > < / select > ;
//或以编程方式创建一个并将其添加到DOM
var select = document.createElement(select);
var option = document.createElement(option);
option.value =1;
option.text =一个;
select.appendChild(option);
document.getElementById(demob)。appendChild(select);
返回false;
}
< / script > 跨度>
trying to do this, a submit type regular button is displayed. when clicked,
it shows a dropdown list, upon selecting a value, another drop down list shows up and then submit.
how do i do this?
here is something i started with...
<!DOCTYPE html> <html> <body> <p>Click the button to trigger a function that will output "Hello World" in a p element with id="demo".</p> <button onclick="myFunction()">Click me</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = "<select>"; } </script> </body> </html>
解决方案
<button onclick="return myFunction()">Click me</button> <p id="demo"></p> <p id="demob"></p> <script> function myFunction() { // append the whole html for a select document.getElementById("demo").innerHTML += "<select><option value='1'>One</option></select>"; // or create one programatically and add it to the DOM var select = document.createElement("select"); var option = document.createElement("option"); option.value = "1"; option.text = "One"; select.appendChild(option); document.getElementById("demob").appendChild(select); return false; } </script>
这篇关于按钮单击以显示下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文