在FF和Chrome中接收用于JavaScript函数的TypeError
Receiving a TypeError in FF and Chrome for JavaScript Function
请帮忙。。。我已经尽了一切努力来纠正Firefox和Chrome中的这个错误。运行函数时收到当前错误。"TypeError:obj1.options不是函数"。我尝试了很多事情,甚至尝试将onclick函数更改为JQuery.click()函数,以及在JQueryDocument.ready函数之间放置。它在IE中工作得很好,但在其他浏览器中会抛出TypeError。事实上,我得到了多个类型错误,一个用于AddMember函数,另一个用于Remove Member。这可能是过时的JavaScript。如有任何帮助,我们将不胜感激。感谢
function RemoveMember(idx, idx2){
//centralizes code to remove selected items from a MULTIPLE SELECT (listbox).
//loops "backward" to maintain valid indexing counters while removing items.
var obj = idx;
var obj2 = idx2;
var nCount = 0;
nCount = obj.options.length - 1;
for ( nCount; nCount > -1; nCount -- ) {
if ( obj.options(nCount).selected == true ) {
var oOption = document.createElement("OPTION");
oOption.text = obj.options(nCount).text;
oOption.value = obj.options(nCount).value;
obj.options.remove(nCount);
//JJK added add back to avail list
obj2.add(oOption);
}
} //for
//sort both listboxes
sortOptions(obj2);
sortOptions(obj);
}
这是完整的html文件,所以你可以看到它的全部。我们本质上有两个列表框,并且有两个带有点击操作的图像,用于将列表项从左侧第一个列表集添加或删除到第二个列表集。
<!-- #include file = "../include/permissions.inc" -->
<!-- #include file = "../Include/adovbs.inc" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<%
CheckPermissions pManagePFI, True
Dim sType, PFIName
Dim objSup, osRS, ret, iSupID
sType = Request.QueryString ("type")
pfid = Request.Form ("pfid")
'Set Type
if sType = "SV" then
sType = "2"
elseif sType = "DC" then
sType = "1"
end if
'Get PFI Name
if not pfid = "" then
set objPFI = Server.CreateObject("LAS.NET.CPFI")
PFIName = objPFI.GetName(clng(pfid))
set objPFI=nothing
end if
function selOptions()
Response.Write "<option value='0'>select</option>"
if sType = "2" then
Response.Write "<option selected value='2'>Servicer</option>"
else
Response.Write "<option value='2'>Servicer</option>"
end if
if sType = "1" then
Response.Write "<option selected value='1'>Document Custodian</option>"
else
Response.Write "<option value='1'>Document Custodian</option>"
end if
end function
function GetSupporters()
set objSup = Server.CreateObject("LAS.NET.CSupporter")
Dim sSupportName, getType
if sType = "2" then
getType = "Servicer"
elseif sType = "1" then
getType = "Document Custodian"
end if
ret = objSup.GetSupportList(cstr(getType), clng(pfid))
Set osRS = UnPersistRS(ret)
if not osRS.EOF then
osRS.MoveFirst
osRS.Filter = "bActive = True"
Do while not osRS.EOF
sSupportName = osRS.Fields("sSupport_Name").Value
iSupID = osRS.Fields("iSupport_ID").Value
Response.write "<option value='" & iSupID & "'>" & sSupportName & "</option>"
osRS.MoveNext
loop
end if
set osRS=nothing
set objSup=nothing
end function
function GetPFISupporters()
if not pfid = "" then
set objPFI = Server.CreateObject("LAS.NET.CPFI")
dim osRS
if sType="2" then
ret = objPFI.GetSupporters("Servicer",clng(pfid))
elseif sType= "1" then
ret = objPFI.GetSupporters("Document Custodian",clng(pfid))
end if
If len(ret) <> 0 then
Set osRS = UnPersistRS(ret)
if not osRS.eof then
Do while not osRS.eof
sSupportName = osRS.Fields("sSupport_Name").Value
iSupID = osRS.Fields("iSupport_ID").Value
Response.write "<option value='" & iSupID & "'>" & sSupportName & "</option>"
osRS.MoveNext
loop
end if
end if
set osRS=nothing
set objPFI=nothing
end if
end function%>
<title>FHLB</title>
<script language="javascript">
function SelectValue(idx, val){
//centralizes code to loop index values in SELECT and highlight
//appropriate item.
var obj = idx;
var nCount = 0;
var nCounter = 0;
nCount = obj.options.length;
for ( nCounter = 0; nCounter < nCount; nCounter ++ ) {
if ( obj.options(nCounter).value == val ) {
obj.selectedIndex = nCounter;
}
}
obj.value = obj.options( obj.selectedIndex ).value ;
}
function OneSelected(idx){
//function to search a fieldset, and determine whether any checkboxes
//have been selected.
var oRows = idx.children(0).children(0).children //the only child of the fieldset is the TABLE.
var nCount = idx.children(0).children(0).children.length;
var nCounter = 0;
var ret = false;
for ( nCounter = 0; nCounter < nCount; nCounter ++ ) {
if ( oRows(nCounter).children(1).children(0).checked == true ) {
ret = true;
break;
}
}
if ( ret == true ){
return true;
}
else{
return false;
}
}
function Validate() {
//alert("Attempted save");
var obj = document.frmFHLBGlobal.MemberList ;
var nCount = 0;
var nCounter = 0;
nCount = obj.options.length;
for ( nCounter = 0; nCounter < nCount; nCounter ++ ) {
obj.options(nCounter).selected = true;
}
document.frmFHLBGlobal.action="process_AssignSupporter.asp";
document.frmFHLBGlobal.submit();
}
function Refresh() {
var obj = document.all.selType;
obj.value = obj.options( obj.selectedIndex ).value;
document.frmFHLBGlobal.action = "AssignSupporter.asp?type=" + obj.value;
document.frmFHLBGlobal.submit();
}
function AddMember(idx1, idx2){
//centralizes code to loop index values in SELECT and highlight
//appropriate item.
var obj1 = idx1;
var obj2 = idx2;
var nCount1 = 0;
var nCounter1 = 0;
var nCount = 0;
//add entries to the assigned box
nCount1 = obj1.options.length;
for ( nCounter1 = 0; nCounter1 < nCount1; nCounter1 ++ ) {
if ( obj1.options(nCounter1).selected == true ) {
var oOption = document.createElement("OPTION");
oOption.text = obj1.options(nCounter1).text;
oOption.value = obj1.options(nCounter1).value;
obj2.add(oOption);
}
}
//remove entries from available box
//loops "backward" to maintain valid indexing counters while removing items.
nCount = obj1.options.length - 1;
for ( nCount; nCount > -1; nCount -- ) {
if ( obj1.options(nCount).selected == true ) {
obj1.options.remove(nCount);
}
}
//sort both listboxes
sortOptions(obj2);
sortOptions(obj1);
}
function RemoveMember(idx, idx2){
//centralizes code to remove selected items from a MULTIPLE SELECT (listbox).
//loops "backward" to maintain valid indexing counters while removing items.
var obj = idx;
var obj2 = idx2;
var nCount = 0;
nCount = obj.options.length - 1;
for ( nCount; nCount > -1; nCount -- ) {
if ( obj.options(nCount).selected == true ) {
var oOption = document.createElement("OPTION");
oOption.text = obj.options(nCount).text;
oOption.value = obj.options(nCount).value;
obj.options.remove(nCount);
//JJK added add back to avail list
obj2.add(oOption);
}
} //for
//sort both listboxes
sortOptions(obj2);
sortOptions(obj);
}
//jjk sort add V2.3.2
function sortOptions(listbox) {
//get listbox values into arrays
var arrValues = new Array()
var arrText = new Array()
var obj = listbox;
var nCount = 0;
var nCounter = 0;
nCount = obj.options.length;
for ( nCounter = 0; nCounter < nCount; nCounter ++ ) {
arrText[nCounter]= obj.options(nCounter).text;
arrValues[nCounter] = obj.options(nCounter).value;
}
var x, y, holder, temp_text1, temp_text2;
// The Bubble Sort method.
for(x = 0; x < arrText.length; x++) {
for(y = 0; y < (arrText.length-1); y++) {
temp_text1 = arrText[y];
temp_text2 = arrText[y+1];
if(temp_text1.toUpperCase() > temp_text2.toUpperCase()) {
holder = arrText[y+1];
arrText[y+1] = arrText[y];
arrText[y] = holder;
//do same for values array to keep their indexes together
holder = arrValues[y+1];
arrValues[y+1] = arrValues[y];
arrValues[y] = holder;
}
}
}
// Update the select box list.
var i;
for(i = 0; i < arrValues.length; i++) {
if(listbox.options[i] == null) {
var oOption = document.createElement("OPTION");
oOption.text = arrText[i];
oOption.value = arrValues[i];
listbox.options[i] = oOption;
}
else {
listbox.options[i].text = arrText[i];
listbox.options[i].value = arrValues[i];
}
}
} //jjk sort end
function goPFI(){
document.frmFHLBGlobal.action ="ViewPFI.asp";
document.frmFHLBGlobal.submit();
}
</script>
<link rel="stylesheet" type="text/css" href="../Style/<%=application("DistrictCode")%>.css">
</head>
<body>
<!-- #include file = "../include/head.inc" -->
<p>
<table align="center" valign="middle" width="50%" border="1" class="InnerTable">
<tr>
<td class="tableheader" width="100%">
<center><font class="tableheadertitletext">Add Supporter for <%=PFIName%></font></center>
</td>
</tr>
<tr><td align="center">
<form name="frmFHLBGlobal" method="Post" action="process_AssignSupporter.asp">
<input type="hidden" name="pfid" value="<%=pfid%>">
<table width="100%" cellpadding="0" cellspacing="0">
<input type="hidden" name="Test">
<tr>
<td align="center">
<fieldset><!------list name and type-------->
<table class="InnerTable" width="100%" border="0">
<tr>
<td class="InnerTableTextSmall">
<b>List Type:</b>
<select name="selType" onchange="Refresh()">
<%=selOptions%>
</select>
</td>
</tr>
</table>
</fieldset>
<fieldset><!------listbox select-------->
<table class="InnerTable" width="100%" border="0">
<tr>
<td width="45%" align="center" class="InnerTableTextSmall">
<b>Available<b><br>
<select name="MainList" MULTIPLE style="width: 200" size="15" ondblclick="AddMember(document.frmFHLBGlobal.MainList, document.frmFHLBGlobal.MemberList);">
<%
'if len(trim(strOptions)) > 0 then
Response.Write GetSupporters()
'end if
%>
</select>
</td>
<td width="10%" align="center" valign="middle">
<img src="../images/<%=application("DistrictCode")%>/add2.gif" name="Add Member(s)" id="Add" onclick="AddMember(document.frmFHLBGlobal.MainList, document.frmFHLBGlobal.MemberList);">
<img src="../images/<%=application("DistrictCode")%>/remove.gif" name="Remove Member(s)" id="Remove" onclick="RemoveMember(document.frmFHLBGlobal.MemberList, document.frmFHLBGlobal.MainList);">
</td>
<td width="45%" align="center" class="InnerTableTextSmall">
<b>Currently Assigned<b><br>
<select name="MemberList" MULTIPLE style="width: 200" size="15" ondblclick="RemoveMember(document.frmFHLBGlobal.MemberList);">
<%=GetPFISupporters()%>
</select>
</td>
</tr>
</table>
</fieldset>
<fieldset>
<table class="InnerTable" width="100%" border="0">
<tr>
<td align="center">
<img src="../images/<%=application("DistrictCode")%>/save.gif" name="Save" id="Save" onclick="Validate()">
<img src="../images/<%=application("DistrictCode")%>/cancel.gif" name="Cancel" id="Cancel" onclick="goPFI()">
</td>
</tr>
</table>
</fieldset>
</td>
</tr>
</table>
</td>
</tr>
</table>
<input type="hidden" name="sType" value="<%=sType%>">
</form>
<!-- #include file = "../include/foot.inc" -->
</body>
</html>
obj.options(nCount)
应该是
obj.options[nCount]
obj
是HTMLSelectElement
对象。HTMLSelectElement
没有options
方法,因此以下内容不正确:
obj.options(nCount) // XXX
HTMLOptionsCollection
对象确实具有options
属性,记录如下:
返回包含此元素所包含的
<option>
元素集的HTMLOptionsCollection
。
HTMLOptionsCollection
有两种方法:
item(index)
-返回给定的基于零的索引处的特定节点(如果超出范围,则为null)namedItem(name)
-返回具有给定DOMString(即字符串)id的特定节点。如果不存在此类命名节点,则返回null
这意味着你应该使用
obj.options.item(nCount)
HTMLOptionsCollection
的父类显示
在JavaScript中,访问
HTMLCollection
对象的代码,为了获得给定HTMLCollection
的项,可以使用方括号语法,而不是直接调用item()
或namedItem()
方法。方括号中的数值与item()
的工作方式相同,字符串值与namedItem()
的工作方式一样。
这意味着你也可以使用
obj.options[nCount]
- Javascript-用于展开数组的递归/for循环
- JavaScript:用于检索属性值的括号表示法
- 是javascript(用于节点)中用于忽略文件的任何微小库
- javascript用于带有html5的自动图像滑块
- JAVASCRIPT-用于变量“;i〃;未定义
- 我的Javascript(用于在ul中重新排序li)在IE中不起作用
- JavaScript 用于查找地点数量的纬度和经度
- Javascript:用于 vs jQuery.each() 与时间延迟
- Javascript用于圆角图像,在Chrome上不起作用
- JavaScript 用于在某些事件发生后执行函数
- JavaScript:用于播放WAV的自定义形状按钮
- JavaScript 用于当用户向下滚动屏幕时弹出的建议框
- JavaScript - 用于 x 轴和 y 轴上的循环
- JavaScript:用于查找链表节点的递归函数返回错误的节点
- 有没有通过 Evernote API 将 JavaScript 用于附件的具体示例
- 正则表达式 javascript 用于检查逗号分隔的数字
- 正则表达式/javascript 用于匹配括号中的值
- JavaScript:用于流媒体的简单 SoundCloud API 示例无法在 Safari 中正常工作
- Javascript 用于将名称值对分配给对象的简写
- Javascript 用于计算带有单选复选框和下拉项的提交表单