Using Javascript to access/change control's property

Set readonly for input text

document.getElementById("ctrl_id").readOnly  = true; //pay attention to the readOnly, it's case sensitive.

 

Set option to unable to select for select control:

<option value="Genre" disabled="disabled">Genre</option>

 

Set select control to disabled (it has no readonly property):

<select disabled="disabled"></select>

 

Add a new option to a select control, it works under firefox 2.x and IE 5.x:

function addOption(select_ctrl, option_value, option_text){
    var ctrl = document.getElementById(selectctl);
    
    if(ctrl == null)
        return;
    
    var doc = ctrl.ownerDocument;
    if (!doc)
        doc = ctrl.document;
        
    var opt = doc.createElement('OPTION');
    opt.value = option_value;
    opt.text = option_text;
    
    ctrl.options.add(opt, ctrl.options.length);
}

 

Delete an option from select control:

selectctl.options[selectctl.selectedIndex] = null;

Delete all options from select control:

selectctrl.options.length = 0;

Change the css for an object:

document.getElementById("ctrl_id").className="SHOWN";

转载于:https://www.cnblogs.com/taotao/archive/2007/08/30/875781.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值