• BootStrap学习1 输入提示


    首先参考这个页面http://www.bootcss.com/javascript.html#typeahead

    我只是把里面最基本的东西抠出来了

    <!DOCTYPE html>
    <html>
        <head>
            <title>Bootstrap 101 Template</title>
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <!-- Bootstrap -->
            <link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
        </head>
        <body>
            <script src="http://code.jquery.com/jquery.js"></script>
            <script src="http://cdnjs.bootcss.com/ajax/libs/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
        </body>
    
        <div class="bs-docs-example" style="background-color: #f5f5f5;">
            <input type="text" class="span3" style="margin: 0 auto;" autocomplete="off"  data-provide="typeahead" data-items="4" data-source="[&quot;Alabama&quot;,&quot;Alaska&quot;,&quot;Arizona&quot;,&quot;Arkansas&quot;,&quot;California&quot;,&quot;Colorado&quot;,&quot;Connecticut&quot;,&quot;Delaware&quot;,&quot;Florida&quot;,&quot;Georgia&quot;,&quot;Hawaii&quot;,&quot;Idaho&quot;,&quot;Illinois&quot;,&quot;Indiana&quot;,&quot;Iowa&quot;,&quot;Kansas&quot;,&quot;Kentucky&quot;,&quot;Louisiana&quot;,&quot;Maine&quot;,&quot;Maryland&quot;,&quot;Massachusetts&quot;,&quot;Michigan&quot;,&quot;Minnesota&quot;,&quot;Mississippi&quot;,&quot;Missouri&quot;,&quot;Montana&quot;,&quot;Nebraska&quot;,&quot;Nevada&quot;,&quot;New Hampshire&quot;,&quot;New Jersey&quot;,&quot;New Mexico&quot;,&quot;New York&quot;,&quot;North Dakota&quot;,&quot;North Carolina&quot;,&quot;Ohio&quot;,&quot;Oklahoma&quot;,&quot;Oregon&quot;,&quot;Pennsylvania&quot;,&quot;Rhode Island&quot;,&quot;South Carolina&quot;,&quot;South Dakota&quot;,&quot;Tennessee&quot;,&quot;Texas&quot;,&quot;Utah&quot;,&quot;Vermont&quot;,&quot;Virginia&quot;,&quot;Washington&quot;,&quot;West Virginia&quot;,&quot;Wisconsin&quot;,&quot;Wyoming&quot;]">
    
        </div>
        <script>
            $('.typeahead').typeahead();
            
        </script>
    </html>

    好了 其实这是个很没营养的例子 使用BootStrap呢 需要引用三个文件  一个是bootstrap.css

    接着就是jQuery 再就是bootstrap.js 

    去这里下载吧http://www.bootcss.com/

    或者引用这个(这下面没有包含CSS)

    <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
            <script src="http://twitter.github.io/bootstrap/assets/js/jquery.js"></script>
            <script src="http://twitter.github.io/bootstrap/assets/js/bootstrap-transition.js"></script>
            <script src="http://twitter.github.io/bootstrap/assets/js/bootstrap-alert.js"></script>
            <script src="http://twitter.github.io/bootstrap/assets/js/bootstrap-modal.js"></script>
            <script src="http://twitter.github.io/bootstrap/assets/js/bootstrap-dropdown.js"></script>
            <script src="http://twitter.github.io/bootstrap/assets/js/bootstrap-scrollspy.js"></script>
            <script src="http://twitter.github.io/bootstrap/assets/js/bootstrap-tab.js"></script>
            <script src="http://twitter.github.io/bootstrap/assets/js/bootstrap-tooltip.js"></script>
            <script src="http://twitter.github.io/bootstrap/assets/js/bootstrap-tooltip.js"></script>
            <script src="http://twitter.github.io/bootstrap/assets/js/bootstrap-tooltip.js"></script>
            <script src="http://twitter.github.io/bootstrap/assets/js/bootstrap-collapse.js"></script>
            <script src="http://twitter.github.io/bootstrap/assets/js/bootstrap-carousel.js"></script>
            <script src="http://twitter.github.io/bootstrap/assets/js/bootstrap-typeahead.js"></script>
            <script src="http://twitter.github.io/bootstrap/assets/js/bootstrap-affix.js"></script>
            <script src="http://twitter.github.io/bootstrap/assets/js/holder/holder.js"></script>
            <script src="http://twitter.github.io/bootstrap/assets/js/holder/holder.js"></script>
            <script src="http://twitter.github.io/bootstrap/assets/js/application.js"></script>

    之后呢 就这么用

    <input type="text" id="myElement"/>
    
            <script type="text/javascript">
            /*js数组的两种定义方式 
            var mycars=["Saab","Volvo","BMW"]; 
            var mycars=new Array("Saab","Volvo","BMW")
            {XX:XX}是对象的一个实例
            person={firstname:"John",lastname:"Doe",age:50,eyecolor:"blue"};
             */
            var mySource = [{ id: 1, name: 'Terry'}, { id: 2, name: 'Mark'}, { id: 3, name: 'Jacob'}];
    
            var jsonString = '[{"label":"System Administrator","value":"1"},{"label":"Software Tester","value":"3"},{"label":" Software Developer","value":"4"},{"label":"Senior Developer","value":"5"},{"label":"Cloud Developer","value":"6"},{"label":"Wordpress Designer","value":"7"}]';
    
            var jsonObj = $.parseJSON(jsonString);
            var sourceArr = [];
    
            for (var i = 0; i < jsonObj.length; i++) {
               sourceArr.push(jsonObj[i].label);
            }
    
            var sourceX=["aaa","bbb","CCC"];
            $('#myElement').typeahead({
                    //source:mySource
                    source:sourceArr
            }); //-----ok
    
    </script>

    这里展示了两种数据源  一种是javascript对象数组  一种是json数据

    其实呢 json数据也是先处理为javascript数组再用的  这里的例子是将这里json的数据处理成了sourceX那种的的形式

    放在了sourceArr中

    好啦 下一个随笔来写如何结合使用ajax

  • 相关阅读:
    20170411linux常用命令
    20170411oracle常用命令
    20170411-oracle 查询指定节点下的所有子节点包括直到叶子节点
    20170329oracle安装教程
    20170329plsql连接oracle
    20170329001怎么让plsql窗口列表保持
    Eclispse 换主题、皮肤、配色,换黑色主题护眼
    zbb20170303使用ssh一直找不到session,报错not found session in current thread
    zbb20170303_ant_build.xml详解
    hdu Farm Irrigation
  • 原文地址:https://www.cnblogs.com/cart55free99/p/3193678.html
Copyright © 2020-2023  润新知