如何在 IE Windows Mobile 5 中向 <SELECT> 添加选项 [英] How to Add options to &lt;SELECT&gt;, in IE Windows Mobile 5

查看:30
本文介绍了如何在 IE Windows Mobile 5 中向 <SELECT> 添加选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试以编程方式向 IE Windows Mobile 中的 SELECT 下拉列表添加选项.

Trying to programmatically add options to a SELECT drop down in IE Windows Mobile.

因为这是 IE Windows Mobile 5,大多数涉及 getElementID 的解决方案都不起作用,所以我不得不求助于更普通的普通 HTML/Java 脚本,下面的示例在 IE 6 和 FF 中工作正常,但因对象不支持此属性或方法"在 Windows Mobile 5 中

Because this is IE Windows Mobile 5, most solutions involving getElementID do not function, so I have had to resort to more plain vanilla HTML /Java script, the example below works fine in IE 6 and FF , but fails with "Object doesn't support this property or method" in Windows Mobile 5

function insertBarcodes()
{
val = document.form1.barcode.value ;
i = document.form1.blist.length;
myNewOption = new Option(val , val ); 
document.form1.blist.options[document.form1.blist.length] =myNewOption ; 
 }
 updateCount();

}

有什么想法吗?

推荐答案

在这里找到答案:

首先我在这里查看了官方参考来源:http://msdn.microsoft.com/en-us/library/bb159677.aspx

First I looked at the official reference source here: http://msdn.microsoft.com/en-us/library/bb159677.aspx

我注意到 selectObj 有一个 add 方法,所以我尝试了它并且它起作用了..

I noted that there is an add method for the selectObj, so I tried it and it worked..

这是工作代码,

function AddSelectOption(selectObj, text, value, isSelected){
  if(selectObj != null && selectObj.options != null){
    var newOpt = new Option('Hello','Hello'); //create the option object
    selectObj.add(newOpt); //it's the .add(option) method
  }
}

谢谢大家

这篇关于如何在 IE Windows Mobile 5 中向 <SELECT> 添加选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆