尝试访问特定选项值以生成弹出窗口

发布于 2024-10-11 12:19:38 字数 2500 浏览 6 评论 0原文

我正在尝试使用单击事件根据所选的特定值生成弹出窗口。我在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不顾 2024-10-18 12:19:39

假设我理解您的问题,请尝试将最后一行替换为以下内容:

var options = document.getElementsByTagName('option');
for(var i = 1; i < options.length; i++) { options[i].addEventListener("click", display, false) }

您正在尝试对元素数组使用 AddEventListener,但这是行不通的。

Assuming I understand your question, try replacing the last line with these:

var options = document.getElementsByTagName('option');
for(var i = 1; i < options.length; i++) { options[i].addEventListener("click", display, false) }

You are trying to use AddEventListener on an array of elements, which won't work.

寄与心 2024-10-18 12:19:39

感谢您的回复。相反,我只是将 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;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文