kojs select綁值(工作)

來源:互聯網
上載者:User

標籤:bind   body   query   event   ons   this   charset   資料   jquery   

<!DOCTYPE html> <html><head>  <meta charset="utf-8" />     <title>select</title>        <script src="jquery-1.10.2.min.js"></script>   <script type="text/javascript" src="knockout-3.2.0.js"></script>    <script>         function MyViewModel()         {            var self = this;  //用self替代this             self.peopleList = ko.observableArray([    { name: "張三", id: "1" },    { name: "李四", id: "2" },    { name: "王五", id: "3" }]); //監控數組self.selectedPeople=ko.observable(0); //記錄已選中的人員值self.peopleChange=function() //選擇某個選項後的事件。{alert(self.selectedPeople()); }         }        $(function () {            ko.applyBindings(new MyViewModel());        });    </script>  </head><body><div><select  data-bind="options: peopleList,              optionsText: ‘name‘, optionsValue:‘id‘,value: selectedPeople, optionsCaption: ‘選擇人員...‘,event: { change: peopleChange}"></select></div></body></html>


=============================================================
options: peopleList  指定綁定資料有哪個對象來。optionsText: ‘name‘ 綁定時顯示欄位為nameoptionsValue:‘id‘  綁定時值欄位為idvalue: selectedPeople  值儲存在哪個對象中optionsCaption: ‘選擇人員...‘ 預設下拉框中的文字event: { change: peopleChange}" 指定onchange事件需要執行的方法
=============================================================




kojs select綁值(工作)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.