您的位置:首页 > 运维架构

今天需要生成一条option记录插入到select,采用dom的方法与先前的方法有所不同

2006-12-22 17:55 405 查看
按DOM方式




//使用dom的方法


$("floatingFrequencyCode").options.insertBefore(createOption(thestr, "01"),


$("floatingFrequencyCode").options[0]);




//则需要此方式来生成optino


function createOption(thetext, thevalue)




...{


var theoption = document.createElement("OPTION");


theoption.innerHTML = thetext;


theoption.value = thevalue;


return theoption;


}



不按DOM方式


function createOption(thetext, thevalue)




...{


var theoption = document.createElement("OPTION");


theoption.text = thetext;


theoption.value = thevalue;


return theoption;


}




$("floatingFrequencyCode").options.add(createOption(thestr, "01"), 0);




//0是插入的位置,如果不写该参数,则直接追加在select尾部

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐