Javascript 选择特定选项时,要求填写文本区域
当选择“其他”时,我需要填充文本区域。 这就是我所拥有的,我想它会有用的。但当选择“其他”且文本区域为空时,将不显示任何内容 html:Javascript 选择特定选项时,要求填写文本区域,javascript,Javascript,当选择“其他”时,我需要填充文本区域。 这就是我所拥有的,我想它会有用的。但当选择“其他”且文本区域为空时,将不显示任何内容 html: getElementsByTagName返回节点列表x是一个字符串。将列表与字符串进行比较总是false。也许你想看看谢谢,这就解决了问题。 <form onsubmit="return validation()"> <span>Reason for inquiry: <span> <select style=
getElementsByTagName
返回节点列表x
是一个字符串。将列表与字符串进行比较总是false
。也许你想看看谢谢,这就解决了问题。
<form onsubmit="return validation()">
<span>Reason for inquiry: <span>
<select style="color:black" name="reasons">
<option value="catering">Catering</option>
<option value="private party">Private Party</option>
<option value="feedback">Feedback</option>
<option id="selectedOther" value="other">Other</option>
</select>
</form>
function validation(){
otherInquiry()
}
function otherInquiry(){
var x = document.getElementById("selectedOther").value;
if (document.getElementsByTagName("select") == x){
if(document.getElementById("txtArea").value == ""){
alert("Please tell us your reason of inquiry")
}
return false;
}
}