• [jQuery编程挑战]004 针对选择框词典式排序


    <!DOCTYPE html>
    <html lang="zh">
        <head>
            <meta charset="utf-8"/>
            <title>针对选择框词典式排序</title>
            <script type="text/javascript" src="../js/jquery-1.11.0.js"></script>
            <script type="text/javascript">
                $(function() {
                    /*$('button').click(function() {
                        var options = $('option');
                        for (var i = 1; i < options.length; i++) {
                            for (var j = 0; j < i; j++) {
                                var currOption = $(options.get(i)),
                                    loopOption = $(options.get(j));
                                if (currOption.text() < loopOption.text()) {
                                    currOption.insertBefore(loopOption);
                                }
                            }
                        }
                    });*/
    
                    $('button').click(function() {
                        var $options = $('option');
                        $options.sort(function(a, b) {
                            if ($(a).text() > $(b).text()) return 1;
                            else return -1;
                        });
                        $('select').html($options);
                    });
                });
            </script>
        </head>
        <body>
            <button>排序</button>
            <select>
                <option>php</option>
                <option>c</option>
                <option>javascript</option>
                <option>css</option>
                <option>html</option>
                <option>python</option>
            </select>
        </body>
    </html>
  • 相关阅读:
    Leetcode: Reverse Integer
    Leetcode: Two Sum
    Leetcode: Path Sum
    make distclean
    makefile 中 foreach
    nor flash 和 nand flash
    端口(port)的安全模式(security mode)
    单片机入门(二)
    单片机入门(一)
    kworker
  • 原文地址:https://www.cnblogs.com/jerry19890622/p/4309887.html
Copyright © 2020-2023  润新知