Js/jquery常用
id属性不能有空格
1. js判断checkebox是否被选中
var ischecked = document.getElementById("xxx").checked //返回false or true
设置选上/不选:document.getElementById("xxx").checked=true/false
Jquery
判断选上:$('#isAgeSelected').attr('checked') // true//false
选上:
$('.myCheckbox').prop('checked', true) or
$('.myCheckbox').attr('checked', true) or
$(".myCheckBox").checked(true);
不选改为false
2. jquery 判断selecte的值
<select name="selector" id="selector">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
$('select[name=selector]').val()
选中Option 1
$('select[name=selector]').val("1");
3. 往Array中存入对象,
var regions = new Array();
var ri = new Object();
ri.id = "";
ri.name = "";
regions.push(ri);
<c:forEach items="${regionList.values}" var="region">
ri = new Object();
ri.id = "${region.id}";
ri.name = "${region.name}";
regions.push(ri);
</c:forEach>
window.regions = regions;
取数据则 Object region = regions[index];
var regionId = region.id;
Note: js中嵌入了<c:foreach>不建议这么用。
4. bind 与 unbind
$("#name").bind("click", (function () {
$("#attrib_UNIQUE_ACTV_PURCHASE").attr('checked', true);
}));
$("#description").bind("click", (function () {
$("#attrib_UNIQUE_ACTV_PURCHASE").attr('checked', false);
}));
$("#message").bind("click", (function () {
$("#name").unbind("click");
$("#description").unbind("click");
}));
增加点击后选中/不选中或解绑后点击效果
click为eventType,还有其他的
| Mouse Events | Keyboard Events | Form Events | Document/Window Events |
|---|---|---|---|
| click | keypress | submit | load |
| dblclick | keydown | change | resize |
| mouseenter | keyup | focus | scroll |
| mouseleave | blur | unload |
5.判断元素是否存在:
How do I test whether an element exists?
Use the .length property of the jQuery collection returned by your selector:
|
1
2
3
4
5
|
if ( $( "#myDiv" ).length ) { $( "#myDiv" ).show();} |
Note that it isn't always necessary to test whether an element exists. The following code will show the element if it exists, and do nothing (with no errors) if it does not:
$( "#myDiv" ).show();
or:
That's as simple as using any of the browser's selecting method, and checking it for a truthy value (generally).
For example, if my element had an id of "find-me", I could simply use...
var elementExists = document.getElementById("find-me");
if (elementExists != null){dosomething}
This is spec'd to either return a reference to the element or null.
Js/jquery常用的更多相关文章
- 【js】前端 js/jquery 常用代码和实践
1.获取某天后几天的日期 //d为传入的日期 days为d后面的几天function getAfterDate(d,days){ var dd = new Date(d); dd.setDate(dd ...
- js+jquery 常用选择器函数
一.获取当前标签 JS: this,如下: <button onclick="fun(this)"></button> Jquery,如下: $(" ...
- js|jquery常用代码
页面重定位: window.location.replace("http://www.bczs.net"); window.location.href = "http:/ ...
- JS,JQUERY 常用笔记
JSON.parse() 转成数组对象 JSON.stringify() 转成JSON字符串
- JS||JQUERY常用语法
cookieEnabled属性语法 通常可以在浏览器的临时文件夹中保存一个文件,此文件可以包含用户信息(比如浏览过什么页面,是否选择了自动登录)等,这个文件被称作cookie,通过cookieEnab ...
- Js jquery常用的身份证号码 邮箱电话等验证
刷了很多博客,https://www.cnblogs.com/hao-1234-1234/p/6636843.html 只有这个比较靠谱.
- js/jquery/html前端开发常用到代码片段
1.IE条件注释 条件注释简介 IE中的条件注释(Conditional comments)对IE的版本和IE非IE有优秀的区分能力,是WEB设计中常用的hack方法.条件注释只能用于IE5以上,IE ...
- js与jquery常用数组方法总结
昨天被问数组方法的时候,问到sort()方法是否会改变原来的数组.本来我猜是不会,也是这么说,马上我又觉得,知识这种东西,不确定的时候直接说不确定或不知道就好,只是凭借着不确定的猜测或者是记忆,害人害 ...
- js和jQuery常用选择器
笔者觉得js是前台基础中的基础,而其选择器则是js基础中的基础,因长期使用框架导致js生疏,所有查资料,回顾一下js的常用选择器: 1.document.getElementById("id ...
随机推荐
- NestJS WebSocket 开始使用
使用NestJs提供WebSocket服务. 本文会在新建项目的基础上增加2个类 Gateway 实现业务逻辑的地方 WebSocketAdapter WebSocket适配器 新建项目 新建一个项目 ...
- ThreadLocal(十一)
一.ThreadLocal源码剖析 ThreadLocal源码剖析 ThreadLocal其实比较简单,因为类里就三个public方法:set(T value).get().remove().先剖析源 ...
- synchronized锁定类方法、volatile关键字及其他(八)
同步静态方法 synchronized还可以应用在静态方法上,如果这么写,则代表的是对当前.java文件对应的Class类加锁.看一下例子,注意一下printC()并不是一个静态方法: public ...
- VM安装kali操作系统
工具:VMware Workstation 15 Pro(15.5.6 build-16341506),kali-linux-2020.2-installer-amd64.iso vm15下载链接:h ...
- python2 与 python3 依赖包冲突问题
原文链接 https://www.2cto.com/database/201805/749294.html 执行pip的时候取的是/usr/bin这里的pip,查看这里是否存在pip3,没有的话需 ...
- Mybatis学习笔记-分页
为何要分页 减少数据处理量 便于前端展示数据 使用Limit分页 语法结构 SELECT * FROM user LIMIT startIndex,pageSize; SELECT * FROM us ...
- Vue3学习第一例:Vue3架构入门
入门 Vue3的教程很少,官方网站实例不好整,另外由于Python的Django也掌握了,学习这个有些让人眼乱.Vue项目创建后,在public目录下面自动生成了一个index.htm,里面有个div ...
- RHCE_DAY01
shell概述 shell是一个程序,它连接了用户和Linux内核,它可以解释用户输入的命令传递给内核,让用户可以更加方便的使用Linux系统 shell 本身并不是内核的一部分,它只是站在内核的基础 ...
- CSS Grid 布局(Grid Layout)完全指南 #flight.Archives003
Title/ CSS Grid 布局(Grid Layout)完全指南 #flight.Archives003 序 : 写完这篇文章后,我准备一直做下去了,包括flight的各个分区,也看到前方的路. ...
- linux c语言学习笔记之守护进程
哈尔滨理工大学软件工程专业08-7李万鹏原创作品,转载请标明出处 http://blog.csdn.net/woshixingaaa/archive/2010/06/06/5651095.aspx 守 ...