尝试访问特定选项值以生成弹出窗口
我正在尝试使用单击事件根据所选的特定值生成弹出窗口。我在使用 if 语句并尝试访问每个特定选项值时遇到问题。你们中的任何人都可以给我一些提示吗?
<select id="offices">
<option value="Choose an Office">Choose an Office</option>
<option value="Residential Education (ResEd)" >Residential Education (ResEd)</option>
<option value="Dean of Students">Dean of Students</option>
<option value="Office of Student Affairs">Office of Student Affairs</option>
<option value="Vice-Provost of Student Affairs">Vice-Provost of Student Affairs</option>
</select>
</div>
函数显示(){
var officearray = [{
Office: "Residential Education (ResEd)",
ID: "725-2800",
Description: "The Office of Residential Education is responsible for developing the policies, programs, and staffing which support the intellectual, educational, and community-building activities in student residences. Second Floor. "
}, {
Office: "Dean of Students",
ID: "723-7833",
Description: "The Dean of Students office is composed of 13 individual administrative units that are concerned with the general welfare of both undergraduate and graduate students, in and out of the classroom. Second floor."
}, {
Office: "Office of Student Activities (OSA)",
ID: "723-2733",
Description: "Services for student organizations, student-initiated major events and programs, and fraternities and sororities. Second floor."
}, {
Office: "Vice-Provost of Student Affairs",
ID: "725-0911",
Description: "The Vice Provost for Student Affairs is responsible to the Provost for providing services and programs to undergraduate and graduate students in support of the academic mission of the University. Second floor."
}]
for(var i = 0; i < officearray.length; i++) {
var o = document.getElementById("offices")
var oString = o.options[o.selectedIndex].value;
newwindow2 = window.open('', 'name', 'height=200, width=150')
var tmp = newwindow2.document
if (oString == officearray[i].Office) {
tmp.writeln(officearray[i].Description)
}
}
}
document.getElementsByTagName('option').addEventListener("click",display,false)
I am trying to use a click event to generate a popup window based off of the specific value chosen. I am having trouble with the if statement and trying to access each specific option value. Can any of you give me some hints?
<select id="offices">
<option value="Choose an Office">Choose an Office</option>
<option value="Residential Education (ResEd)" >Residential Education (ResEd)</option>
<option value="Dean of Students">Dean of Students</option>
<option value="Office of Student Affairs">Office of Student Affairs</option>
<option value="Vice-Provost of Student Affairs">Vice-Provost of Student Affairs</option>
</select>
</div>
function display(){
var officearray = [{
Office: "Residential Education (ResEd)",
ID: "725-2800",
Description: "The Office of Residential Education is responsible for developing the policies, programs, and staffing which support the intellectual, educational, and community-building activities in student residences. Second Floor. "
}, {
Office: "Dean of Students",
ID: "723-7833",
Description: "The Dean of Students office is composed of 13 individual administrative units that are concerned with the general welfare of both undergraduate and graduate students, in and out of the classroom. Second floor."
}, {
Office: "Office of Student Activities (OSA)",
ID: "723-2733",
Description: "Services for student organizations, student-initiated major events and programs, and fraternities and sororities. Second floor."
}, {
Office: "Vice-Provost of Student Affairs",
ID: "725-0911",
Description: "The Vice Provost for Student Affairs is responsible to the Provost for providing services and programs to undergraduate and graduate students in support of the academic mission of the University. Second floor."
}]
for(var i = 0; i < officearray.length; i++) {
var o = document.getElementById("offices")
var oString = o.options[o.selectedIndex].value;
newwindow2 = window.open('', 'name', 'height=200, width=150')
var tmp = newwindow2.document
if (oString == officearray[i].Office) {
tmp.writeln(officearray[i].Description)
}
}
}
document.getElementsByTagName('option').addEventListener("click",display,false)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设我理解您的问题,请尝试将最后一行替换为以下内容:
您正在尝试对元素数组使用 AddEventListener,但这是行不通的。
Assuming I understand your question, try replacing the last line with these:
You are trying to use AddEventListener on an array of elements, which won't work.
感谢您的回复。相反,我只是将 onlick 事件更改为 onchange 并摆脱了 addEventListener 期间。然后,我使用符合 W3C 的事件处理程序来处理更改事件。
<代码>
document.getElementById("办公室").onchange=显示;
Thanks for the response. Rather I just changed the onlick event to onchange and got rid of the addEventListener period. I then used the W3C compliant event handler to handle the change event.
document.getElementById("offices").onchange=display;