Home >Web Front-end >JS Tutorial >Summary of methods for getting the value selected in the check box using Jquery and angularjs_jquery
In our usual development, sometimes we need to obtain the value selected in the check box and all the information about the row selected in the check box. A little trick at this time is that we can put all the information we want to obtain into the value of the check box. In this way, when we can obtain the selected value of the check box, it is equivalent to obtaining the information of the current row.
Select all and select none:
var bischecked=$('#cboxchecked').is(':checked'); var fruit=$('input[name="orders"]'); fruit.prop('checked',bischecked);
Why do we use prop instead of attr here? This is because
For the inherent attributes of the HTML element itself, use the prop method when processing.
For our own custom DOM attributes of HTML elements, when processing, use the attr method.
Get the selected value:
$('input[name="orders"]:checked').each(function(){ var sfruit=$(this).val(); var orders=sfruit.split(","); var reminder=new Object(); reminder.merchantId=orders[0]; reminder.orderCode=orders[1]; reminder.userId=orders[2]; });
angularjs implementation:
Using angularjs we don’t have to operate the dom, we only need to care about the status of this value;
First take a look at the html code:
<!DOCTYPE html> <html data-ng-app="App"> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script> <script src="script2.js"></script> </head> <body data-ng-controller="AddStyleCtrl"> <div>Choose Tags</div> <div> <div>You have choosen:</div> <hr> <label data-ng-repeat="selectedTag in selectedTags"> (({{selectedTag}})) </label> <hr> <div data-ng-repeat="category in tagcategories"> <div>{{ category.name }}</div> <div data-ng-repeat="tag in category.tags"> <div> <input type="checkbox" id={{tag.id}} name="{{tag.name}}" ng-checked="isSelected(tag.id)" ng-click="updateSelection($event,tag.id)"> {{ tag.name }} </div> </div> <hr> </div> </div> <pre class="brush:php;toolbar:false">{{selected|json}}
{{selectedTags|json}}