HTML form readonly SELECT tag/input

前端 未结 30 3055
陌清茗
陌清茗 2020-11-22 08:28

According to HTML specs, the select tag in HTML doesn\'t have a readonly attribute, only a disabled attribute. So if you want to keep

30条回答
  •  长情又很酷
    2020-11-22 08:51

    I managed it by hiding the select box and showing a span in its place with only informational value. On the event of disabling the .readonly class, we need also to remove the .toVanish elements and show the .toShow ones.

     $( '.readonly' ).live( 'focus', function(e) {
                    $( this ).attr( 'readonly', 'readonly' )
                    if( $( this ).get(0).tagName == 'SELECT' ) {
                        $( this ).before( '' 
                                + $( this ).find( 'option:selected' ).html() + '' )
                        $( this ).addClass( 'toShow' )
                        $( this ).hide()
                }
        });
    

提交回复
热议问题