兼顾php和jquery新版本的checkbox的写法
<input type="checkbox" class="scate_item" name="scategories[]" value="1" />
<input type="checkbox" class="scate_item" name="scategories[]" value="2" />
<input type="checkbox" class="scate_item" name="scategories[]" value="3" />
对php语言来说,checkbox的name后必须有中括号"[]",否则$_POST获取到的只是checkbox的最后一个选中值,但加上后在高版本的jquery中无法使用类似下面的写法来判断选中的个数之类的验证:
var selected_scates_num = $("input[type=checkbox][name=scategories[]]:checked").length;
if( selected_scates_num < 1 || selected_scates_num > 2){
$("#scategory_notice").show();
$("input[type=checkbox]:first").focus();
result = false;
}else{
$("#scategory_notice").hide();
}
jquery1.3.x版本的好像可以,不过可以稍微变通一下,使用样式来取:
var selected_scates_num = $("input.scate_item[type=checkbox]:checked").length;
if( selected_scates_num < 1 || selected_scates_num > 2){
$("#scategory_notice").show();
$("input.scate_item[type=checkbox]:first").focus();
result = false;
}else{
$("#scategory_notice").hide();
}
兼顾php和jquery新版本的checkbox的写法的更多相关文章
- jQuery Raion, Select, CheckBox selector function
Radio jQuery("input[type=checkbox][name='fbCqscsf.cqzdycqk']").not("[value=1]"). ...
- jquery中选择checkbox拼接成字符串,然后到后台拆分取值
jquery中选择checkbox拼接成字符串,然后到后台拆分取值 js中的代码 $("#btn").click(function(){ var chenked=$("i ...
- jquery如何获取checkbox的值
jquery如何获取checkbox的值 一.总结 一句话总结:就是通过jquery获取哪些对应name的checkbox,然后找出:check(被选中的),然后通过jquery的each遍历获取这些 ...
- 使用jQuery获取radio/checkbox组的值的代码收集
<!-- $("document").ready(function(){ $("#btn1").click(function(){ $("[na ...
- 第7章 jQuery插件的使用和写法
第7章 jQuery插件的使用和写法 插件又称扩展,是一种遵循一定规范的应用程序接口写出来的程序. 插件的编写思想基于面向对象. 获取最新的插件可以查看jquery官网:http://plugins. ...
- JQuery事件的链式写法
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- 关于 jQuery中 function( window, undefined ) 写法的原因
今天在读 jQuery 源码的时候,发现下面的写法: (function(window,undefined){ ...// code goes here })(window); window 作为参数 ...
- jquery向上滚动页面的写法
jquery向上滚动页面的写法<pre> $('.arrow_top').on('click',function () { $body = (window.opera) ? (docume ...
- jquery radio、 checkbox、 select 操作
转载:http://www.haorooms.com/post/checkandselect $("input[id^='code']");//id属性以code开始的所有inpu ...
随机推荐
- 【RHEL7/CentOS7防火墙之firewall-cmd命令详解】
目录 Firewalld zone firewall-cmd 开始配置防火墙策略 总结 Redhat Enterprise Linux7已默认使用firewalld防火墙,其管理工具是firewall ...
- poj 3420 Quad Tiling (状压dp+多米诺骨牌问题+矩阵快速幂)
还有这种操作?????? 直接用pre到now转移的方式构造一个矩阵就好了. 二进制长度为m,就构造一个长度为1 << m的矩阵 最后输出ans[(1 << m) - 1][( ...
- JS中常用开发知识点
JS中常用开发知识点 1.获取指定范围内的随机数 2.随机获取数组中的元素 3.生成从0到指定值的数字数组 等同于: 4.打乱数字数组的顺序 5.对象转换为数组 //注意对象必须是以下格式的才可以通 ...
- GitHub上传项目,使用desktop(客户端)教程
GitHub上传项目,使用desktop(客户端)教程 搜索“GitHub上传项目”,能得到很多相关的文章教程,里面讲的都特别麻烦,要弄什么ssh之类的,可算是吓坏了我,使我非常的怀疑为什么GitH ...
- CSS解决ul下面最后一个li的margin
1.运用css3的nth-child(3n): <!DOCTYPE html> <html> <head> <meta charset="UTF-8 ...
- js常用事件及事件对象
- 【codeforces 743E】Vladik and cards
[题目链接]:http://codeforces.com/problemset/problem/743/E [题意] 给你n个数字; 这些数字都是1到8范围内的整数; 然后让你从中选出一个最长的子列; ...
- MyBatis学习总结(1)——MyBatis快速入门
一.Mybatis介绍 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis可以 ...
- UVALive 5545 Glass Beads
Glass Beads Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Origin ...
- PatentTips - Object-oriented processor architecture and operating method
BACKGROUND OF THE INVENTION The present invention relates to processors and computer systems. More s ...