分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

常用Js笔记,以后可能用得上

发布时间:2023-09-06 01:54责任编辑:胡小海关键词:暂无标签
 ?<div class="order_head"> ???????????????<table> ???????????????????<thead> ???????????????????????<tr> ???????????????????????????<th class="talb1"> ???????????????????????????????商品 ???????????????????????????????<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()

常用Js笔记,以后可能用得上

原文地址:https://www.cnblogs.com/opts/p/9054754.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved