Javascript 在Select元素的Option元素内获取自定义属性

Javascript 在Select元素的Option元素内获取自定义属性,javascript,html,internet-explorer,firefox,google-chrome,Javascript,Html,Internet Explorer,Firefox,Google Chrome,可能重复: 我试图支持一些旧代码,在html中的Select元素中有一个option元素: <select onChange="selectURL(this)" style="font-family:Arial; font-size:12;" id="select1" name="select1"> <option ThisCourse="80921" TITLE="- _ ~ : / = ’ ; . , ? ) (.2\" CLASS="" ID="a3688905

可能重复:

我试图支持一些旧代码,在html中的Select元素中有一个option元素:

<select onChange="selectURL(this)" style="font-family:Arial; font-size:12;" id="select1" name="select1">

<option ThisCourse="80921" TITLE="- _ ~ : /  =  ’ ; . , ?  ) (.2\" CLASS="" ID="a368890534077645903f263b5ddc105f" VALUE="/Eclass/CourseFrames.asp?vcCourseGUID=a368890534077645903f263b5ddc105f&amp;vcCourseName=%2D+%5F+%7E+%3A+%2F++%3D++%92+%3B+%2E+%2C+%3F++%29+%28%2E2%5C&amp;vcCourseID=80921&amp;NewWin=0&amp;language=">- _ ~ : /  =  ’ ; . , ?  ) (.2\</option>

- _ ~ : /  =  ’ ; . , ?  ) (.2\
该站点上运行了一些javascript,它正在尝试这样做:

for (i=0; i<SelectElement.options.length;i++)
if (SelectElement.options[i].ThisCourse == CourseID)
SelectElement.selectedIndex = i
对于(i=0;i尝试:

您应该使用HTML5的“数据-”属性


尝试使用getAttribute方法而不是访问属性,如下所示

if (SelectElement.options[i].getAttribute('ThisCourse') == CourseID)

IE通常将属性值和属性视为相同的,但它们是不同的。

因为您已经找到了答案,所以可能需要删除您的问题。
if (SelectElement.options[i].getAttribute('ThisCourse') == CourseID)