0
点赞
收藏
分享

微信扫一扫

JavaScript对Select的子元素Option的操作

司马吹风 2023-02-07 阅读 94


javascript_删除所有select下面的option的方法

/增加之前删除所有option
while ( length != 0 ) {
var length = document . getElementById ( 'courseorder' ) . options . length ;
for ( var i = 0 ; i & lt ; length ; i ++ ) {
document . getElementById ( 'courseorder' ) . options . remove ( i ) ;
length = length / 2 ;
}
}



javascript_创建一个option节点

op = document . createElement ( "option" ) ;
op . value = 0 ;
//表明没有安排到科次
te = document . createTextNode ( "没有安排到课次" ) ;
op . appendChild ( te ) ;
document . getElementById ( "courseorder" ) . appendChild ( op ) ;



举报

相关推荐

0 条评论