Copy selected item's text from select control html

后端 未结 4 1230
说谎
说谎 2021-01-17 05:11

I have a select control with pre defined values and I want my users to be able to copy the selected item\'s text with CTRL + C

I don\'t want them to be able to chang

4条回答
  •  感情败类
    2021-01-17 05:33

    As far as I know, it is not possible to mark the text of a option element. Copy text into clipboard without flash is impossible, too.

    This solution is not the best, but it's the simplest:

    
    
    
    
    
    
    
    

    -

    $('body').on('change', 'select', function() {
        $('input').val($(this).find(":selected").text()).select();
    })
    

    http://jsfiddle.net/5C3Q9/2/

    Just copy the text into a input field, so the user can select and copy it.

提交回复
热议问题