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 ...
随机推荐
- Collection集合工具类
Ⅷ.Collections 工具类 java.util.Collections Collections 集合工具类,用来对集合进行操作,部分重要方法如下: 1.public static <T& ...
- 简单设计一个onedata指标管理体系
以阿里云的maxcompute的数据仓库架构为例, 从上往下定义, dwp的数据,来源是dws+dim,最主要是dws.这里不讨论dim的作用. dws的数据来源于dwd. dwd的数据来源于ods. ...
- Spring总结之AOP
一.Spring AOP简介(百度百科) 面向切面编程(也叫面向方面编程):Aspect Oriented Programming(AOP),是软件开发中的一个热点,也是 Spring 框架中的一个重 ...
- 测试笔记01-Git
Git工具 Git 一个分布式版本管理工具, 学习资料: https://www.liaoxuefeng.com/wiki/896043488029600/1317161920364578 其中:解决 ...
- springboot-5-持久层技术
整合mybatis 流程: 导入依赖: 除了mybaits还有mysql和jdbc依赖 <!--mybatis--> <dependency> <groupId>o ...
- 【LeetCode】94. 二叉树的中序遍历
94. 二叉树的中序遍历 知识点:二叉树:递归:Morris遍历 题目描述 给定一个二叉树的根节点 root ,返回它的 中序 遍历. 示例 输入:root = [1,null,2,3] 输出:[1, ...
- Angular封装WangEditor富文本组件
富文本组件是web程序中很常用的一个组件,特别是要开发一个博客,论坛这类的网站后台. 得益于Angular的强大,封装WangEditor组件非常简单 1.使用yarn或者npm安装wangedito ...
- odoo学习笔记create函数
@api.multi def create_order_sale(self): """""" stage_list = [] for ord ...
- 解决org.hibernate.LazyInitializationException的正确姿势
项目运行过程中,一个报错信息,报错信息如下: org.hibernate.LazyInitializationException: could not initialize proxy [xxx.do ...
- 构建前端第9篇之(上)---Vue组件引入,使用
张艳涛写于2020-1-25日 一.想写下vue引入组件和插件的理解 今天是星期一,周末也看俩两天,在这个几天了,比较迷,主要是从开始学习import指令开始的,import 是es6的语法, imp ...