本来可以通过document对象的getElementsByName方法来获得,但经测试IE下有问题 所以建议采用document对象的getElementById方法: function getObject(id) { var obj=null; eval("obj=document.getElementById('"+id+"');"); return obj; } 使用方法: 将form中的select 、check 的ID属性初使与Name属性一样 var name1=getObject("name1");
就是为了避免这个方法才有这样的问题的哦 这个方法获得的就不是这样的页面对象了。var wxcsId = "selectTopicId"+j; var sxcsId = "checkTopicId"+j; var wxcs = window.document.getElementsByName(wxcsId)[0]; var sxcs = window.document.getElementsByName(sxcsId)[0]; window.alert(addForm.selectTopicId0.selectedIndex); var fl = addForm.selectTopicId0.selectedIndex; var item = new Option(wxcs.options[fl].text,wxcs.options[fl].value);这样就达不到Option(addForm.selectTopicId0.options[f1].text,addForm.selectTopicId0.options[f1].value);这个效果了 我这个是为了一个select multiple=true的2个文本框选择信息,但是我这个表单中有多条记录,每一条记录就会有2个这样select控件 所以请大家帮帮忙
所以建议采用document对象的getElementById方法:
function getObject(id)
{
var obj=null;
eval("obj=document.getElementById('"+id+"');");
return obj;
}
使用方法:
将form中的select 、check 的ID属性初使与Name属性一样
var name1=getObject("name1");
var sxcsId = "checkTopicId"+j;
var wxcs = window.document.getElementsByName(wxcsId)[0];
var sxcs = window.document.getElementsByName(sxcsId)[0];
window.alert(addForm.selectTopicId0.selectedIndex);
var fl = addForm.selectTopicId0.selectedIndex;
var item = new Option(wxcs.options[fl].text,wxcs.options[fl].value);这样就达不到Option(addForm.selectTopicId0.options[f1].text,addForm.selectTopicId0.options[f1].value);这个效果了
我这个是为了一个select multiple=true的2个文本框选择信息,但是我这个表单中有多条记录,每一条记录就会有2个这样select控件 所以请大家帮帮忙
var obj = eval("form."+selectName);