商品
- <label><input type="checkbox" class="tgbox3"> 全选 </label>
- </th>
- <th > 价格 </th>
- <th > 数量 </th>
- <th > 总额 </th>
- <th > 状态 </th>
- <th > 操作 </th>
- </tr>
- </thead>
- </table>
- </div>
- <table class="order_body">
- <thead>
- <tr>
- <th colspan="6">
- <div class="mergeckb">
- <input value="255" type="checkbox" class="tgbox" name="mk" />
- </div>
- <p > 订单号:<i>DS180404111619136495</i></p>
- <p > 下单时间:<i>2018/4/4 11:16:19</i></p>
- </th>
- </tr>
- </thead>
- <tbody>
- </tbody>
- </table>
- // 关键字搜索
- $("#kwdKeyInput").focus(function () {
- document.onkeydown = function (evt) {
- var Withevt = (evt) ? evt : ((window.event) ? window.event : "");
- var keyCode = Withevt.keyCode || Withevt.which || Withevt.charCode;
- if (keyCode == 13) {
- $('.or-search ul li button').trigger("click");
- }
- }
- })
- // 全选
- $(".tgbox3").click(function () {
- // 取消全选
- if (!this.checked) {
- $('input[class="tgbox"]:checkbox:checked');
- var cboxs = $('input[class="tgbox"]:checkbox:checked');
- $.each(cboxs, function (index, e) {
- removeToCookie($(e).val())
- });
- }
- $('.tgbox').prop("checked", this.checked);
- $(".many").text($("thead input[name='mk']:checked").length);
- var cboxs = $('input[class="tgbox"]:checkbox:checked');
- var cids = [];
- $.each(cboxs, function (index, e) {
- cids.push($(e).val());
- });
- addIdToCookie("," + cids);
- });
- // 选框选中事件
- $('input[class="tgbox"]').click(function () {
- $(".tgbox3").prop("checked", $('input[name="mk"]').length == $('input[name="mk"]:checked').length);
- if (this.checked) {
- addIdToCookie("," + $(this).val());
- } else {
- removeToCookie($(this).val());
- }
- });
- // 数组去重
- function distinct(arr) {
- var len = arr.length;
- arr.sort();
- for (var i = len - 1; i> 0; i--) {
- if (arr[i] == "") { arr.splice(i, 1); }
- if (arr[i] == arr[i - 1]) {
- arr.splice(i, 1);
- }
- }
- return arr;
- }
- // 移除数组
- function removeToCookie(id) {
- var cookie = getCookie("orderIds") || "";
- var cookieArray = cookie.split(",");
- var idArray = id.split(",");
- if (cookie.indexOf(id)>= 0) {
- $.each(cookieArray, function (index, item) {
- $.each(idArray, function (index2, iditem) {
- if (iditem == item) {
- cookieArray.splice(index, 1);
- }
- });
- });
- delCookie("orderIds");
- setCookie("orderIds", cookieArray.join(","), 10);
- }
- $(function () {
- // 加载时选中之前选中项
- $('.tgbox').each(function () {
- var allCookie = getCookie("orderIds") || "";
- if (allCookie.indexOf($(this).val())>= 0) {
- $(this).prop('checked', true);
- }
- });
- // 如果选中项等于当前表单所有项, 则说明是全选.
- $(".tgbox3").prop("checked", $('input[name="mk"]').length == $('input[name="mk"]:checked').length);
- })
获取表单某个 name 为 mk 的 input 框
$('input[name="mk"]')
获取某个下拉框选中的文本 / 值
- $("#RemitCurrency option:selected").text()
- $("#RemitCurrency option:selected").val()
获取单选框选中的值
$('input:radio:checked').val()
来源: http://www.bubuko.com/infodetail-2606112.html