<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # AngularJS與單選框及多選框的雙向動態綁定 贈人玫瑰,手留余香。若您感覺此篇博文對您有用,請花費2秒時間點個贊,您的鼓勵是我不斷前進的動力,共勉! AngularJS?在?<input?type="text"?/>?中實現雙向動態綁定十分簡單,如下所示: <input?type="text"?ng-model="topic.title"?/> 只需要用ng-model?與?$scope?中的屬性對應,即實現了type=”text”?的雙向動態綁定。當?<input?type="radio"?/>?及?<input?type="checkbox"?/>?時情況略有不同: ### 1.?<inputtype="radio"?/>? ~~~ <input type="radio" name="person-action" value="go_home" ng-model="person.action" />回家 <input type="radio" name="person-action" value="go_to_school" ng-model="person.action" />回學校 ~~~ ? ? ? 通過?value?屬性指定選中狀態下對應的值,并通過?ng-model?將單選框與?$scope?中的屬性對應,便實現了?type=”radio”?時的雙向動態綁定。 ### 2.?<input?type="checkbox"?/>? ~~~ <input type="checkbox" ng-true-value="true" ng-false-value="false" ng-model="phone.play_sound" />鈴聲 <input type="checkbox" ng-true-value="true" ng-false-value="false" ng-model="phone.play_vibrate" />震動 <input type="checkbox" ng-true-value="true" ng-false-value="false" ng-model="phone.play_lights" />呼吸燈 ~~~ 通過AngularJS?的內置指令?ng-true-value?和?ng-false-value?,指定多選框在選中和未選中狀態下對應的值,再通過ng-model?將其與?$scope?中的屬性對應,便實現了type=”checkbox”?的雙向動態綁定。 但是理想跟現實總是相差太多,在實際操作過程中還是出現了問題。應該是ng-repeat中scope作用域的問題。 經過一番搜索、調試,自己終于將此問題解決了,效果圖如下: ![](https://box.kancloud.cn/2016-03-02_56d6ad931982e.jpg) ### 核心源碼 ### js ~~~ var str = ""; // 原來存放選中的項 $scope.Selected = false; //默認未選中 var choseArr=[]; // 定義數組用于存放前端顯示 $scope.check = function(z,x){ console.log("HUY:"); console.log(z); console.log("HUYU:"); console.log(x); if (x == false) { // 選中 str = str + z + ','; } else { str = str.replace(z + ',', ''); // 取消選中 } choseArr = (str.substr(0,str.length-1)).split(','); console.log("HY:"); console.log(choseArr); $scope.number_request = choseArr.length; // 前端顯示所選數量 $scope.content_request = choseArr; // 前端顯示所選請求ID }; ~~~ ### Html ~~~ <tr ng-repeat="item in querydata"> <td ng-bind="$index+1">1</td> <td><a ui-sref="#">{{item.postid}}</a></td> <td>{{item.medname}}</td> <td>{{item.medfact}}</td> <td>{{item.medcnt}}</td> <td>{{item.remark}}</td> <td>{{item.tel}}</td> <td>{{item.post_time}}</td> <td><input id={{item.postid}} type="checkbox" ng-model="Selected" ng-click="check(item.postid,Selected)" /></td> </tr> ~~~ 參考文獻: [http://www.oschina.net/translate/handling-checkboxes-and-radio-buttons-in-angular-forms](http://www.oschina.net/translate/handling-checkboxes-and-radio-buttons-in-angular-forms) [http://www.cnblogs.com/CheeseZH/p/4517701.html](http://www.cnblogs.com/CheeseZH/p/4517701.html) [http://www.bubuko.com/infodetail-954078.html](http://www.bubuko.com/infodetail-954078.html) ?
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看