Javascript 在html5中显示书面文本的警报框
我有一个下拉列表。当某人单击下拉列表中的“其他”选项时,会出现一个空行,允许某人编写自己的请求。我想创建一个警告框,显示某人在空白行中用大写字母写的内容。我该怎么做 这是我的密码:Javascript 在html5中显示书面文本的警报框,javascript,html,object,options,Javascript,Html,Object,Options,我有一个下拉列表。当某人单击下拉列表中的“其他”选项时,会出现一个空行,允许某人编写自己的请求。我想创建一个警告框,显示某人在空白行中用大写字母写的内容。我该怎么做 这是我的密码: <form action=""> <select name="requests" onchange ="checkIfOther();" id="dropDown1"> <option value="blank"></option> <op
<form action="">
<select name="requests" onchange ="checkIfOther();" id="dropDown1">
<option value="blank"></option>
<option value="good morning sir">Good Morning Sir</option>
<option value="temperature">The current temperature is _____ centigrade.</option>
<option value="other">Other</option>
</select>
</form>
</p>
<button onclick="myFunction()" value>Submit</button>
<div id="other" style="display:none">
<br><br><label>Optional Request: </label><input type="text" id="otherText"/>
</div>
</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>
<script>
function myFunction(){
var x=document.getElementById("dropDown1");
alert("You have chosen: " + x.options[x.selectedIndex].text);
if(x.value == "other"){
b=document.getElementById("other");
alert("You have chosen: " + b.text); //what do I do?
}
}
</script>
早上好,先生
当前温度为摄氏度。
其他
提交
可选请求:
函数checkIfOther(){
a=document.getElementById(“下拉列表1”);
如果(a.值=“其他”)
document.getElementById(“其他”).setAttribute(“样式”,“显示:内联”);
其他的
document.getElementById(“其他”).setAttribute(“样式”,“显示:无”);
}
函数myFunction(){
var x=document.getElementById(“dropDown1”);
警报(“您已选择:”+x.options[x.selectedIndex].text);
如果(x.value==“其他”){
b=document.getElementById(“其他”);
警报(“您已选择:”+b.text);//我该怎么办?
}
}
尝试使用Jquery,下面是代码:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
function myFunction(){
alert('You have chosen: '+$("#otherText").val());
}
function checkIfOther()
{
$("#otherText").val('');
($("#dropDown1").val() == 'other') ? $("#other").show() : $("#other").hide();
}
</script>
函数myFunction(){
警报('您已选择:'+$(“#其他文本”).val());
}
函数checkIfOther()
{
$(“#其他文本”).val(“”);
($(“#dropDown1”).val()=‘其他’?$(“#其他”).show():$(“#其他”).hide();
}
让我知道这有用吗?但我做了类似的事情
<script type="text/javascript">
function mySubmit(){
var x=document.getElementById("dropDown1");
if(x.value == "other"){
alert("You have chosen: " + otherText.value);
}
else {
alert("You have chosen: " + x.options[x.selectedIndex].text);
}
}
</script>
函数mySubmit(){
var x=document.getElementById(“dropDown1”);
如果(x.value==“其他”){
警报(“您已选择:“+otherText.value”);
}
否则{
警报(“您已选择:”+x.options[x.selectedIndex].text);
}
}
您所说的“弹出窗口”是什么意思?浏览器窗口?还是浮动div?还是警报框?什么是“这个请求”?你是指用户输入的“其他”吗?听起来像是一个浮动的divBy弹出窗口,我是指一个警报框。请求意味着,如果您在另一个文本框中键入内容并单击“提交”按钮,则会弹出一个警告框,提示“您已选择:____;。”(在下划线中是您在另一部分中键入的内容。)