实用Javascript代码片段
清除select下拉选项,添加并选择特点选项
$('#mySelect')
.find('option')
.remove()
.end()
.append('<option value="whatever">text</option>')
.val('whatever')
;
为字符串添加endsWith的方法
String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
ref :http://stackoverflow.com/questions/280634/endswith-in-javascript
同理,字符串startsWith方法
if (typeof String.prototype.startsWith != 'function') {
// see below for better implementation!
String.prototype.startsWith = function (str){
return this.indexOf(str) === 0;
};
}
ref : http://stackoverflow.com/questions/646628/how-to-check-if-a-string-startswith-another-string
为数组添加remove方法
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
ref: http://ejohn.org/blog/javascript-array-remove/#postcomment
判断HTML元素是否有子元素
if ( $('#myfav').children().size() > 0 ) {
// do something
}
or
if ($('#myfav').is(':parent')) {
// do something
}
ref:http://stackoverflow.com/questions/1526873/jquery-if-div-id-has-children
实用Javascript代码片段的更多相关文章
- 转--Android实用的代码片段 常用代码总结
这篇文章主要介绍了Android实用的代码片段 常用代码总结,需要的朋友可以参考下 1:查看是否有存储卡插入 复制代码 代码如下: String status=Environment.getE ...
- 精心收集的 48 个 JavaScript 代码片段,仅需 30 秒就可理解!
原文:https://github.com/Chalarangelo/30-seconds-of-code#anagrams-of-string-with-duplicates 作者:Chalaran ...
- 精心收集的 48 个 JavaScript 代码片段,仅需 30 秒就可理解
原文:Chalarangelo 译文:IT168 https://github.com/Chalarangelo/30-seconds-of-code#anagrams-of-string-with ...
- 精心收集的48个JavaScript代码片段,仅需30秒就可理解
源文链接 :https://github.com/Chalarangelo/30-seconds-of-code#anagrams-of-string-with-duplicates 该项目来自于 G ...
- 绝对应当收藏的10个实用HTML5代码片段(转)
HTML5绝对是一个流行元素,受到如此多的公司组织的追捧,作为极客来说,岂能错过呢?在今天这篇文章中,我们将分享一些超实用的HTML5的代码片段,相信大家一定会喜欢! 正确的嵌入flash 如果你经常 ...
- 超实用的 JavaScript 代码片段( ES6+ 编写)
Array 数组 Array concatenation (数组拼接) 使用 Array.concat() ,通过在 args 中附加任何数组 和/或 值来拼接一个数组. const ArrayCon ...
- 实用jQuery代码片段
maco精选的一些jQuery代码,也许你从中可以举一反三[代码] [JavaScript]代码001<p>002 <h3><span >★ 使用jQuery ...
- 精彩 JavaScript 代码片段
1. 根据给定的条件在原有的数组上,得到所需要的新数组. ——<JavaScript 王者归来> var a = [-1,-1,1,2,-2,-2,-3,-3,3,-3]; functio ...
- 为开发者准备的9个实用PHP代码片段
一.查看邮件是否已被阅读 当你发送邮件时,你肯定很想知道你的邮件是否已被对方查看.下面的代码就能实现记录阅读你邮件的IP地址,还有实际的阅读日期和时间. error_reporting(0);Head ...
随机推荐
- 【ACM - 搜索模板】
[广搜模板] #include <iostream> #include <stdio.h> #include <string.h> #include <que ...
- fopen()及相关函数使用
函数简介 函数功能:打开一个文件 函数原型:FILE * fopen(const char * path,const char * mode); ],_wfopen 所需库:<stdio.h&g ...
- wp7 BaseDictionary<TKey, TValue>
/// <summary>/// Represents a dictionary mapping keys to values./// </summary>/// /// &l ...
- hdu 1754 单点更新
题意:很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.这让很多学生很反感.不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问.当然,老师 ...
- 【现代程序设计】加分作业1-对Stack的理解
要求:本次加分作业是要阅读这篇文章“ Stack的三种含义”,以及文章下方的评论,然后做出总结. ----------------------------------------华丽的分割线----- ...
- Ubuntu常用命令大全(转)
点评:Ubuntu常用命令大全,学习ubuntn系统的朋友可以收藏下,用ctrl+F查找即可 一.文件/文件夹管理 ls 列出当前目录文件(不包括隐含文件) ls -a 列出当前目录文件(包括隐含文件 ...
- PHP文件处理类
/** * 文件读写类 * 读取时,支持跳过N个/行字符然后再读取M个/行字符 * 支持每次读取时使用回调函数 * * 示例: * $file = new File('a.txt', 'r'); * ...
- eclipse下导入工程的小问题
- 【HTML5】表单元素
* datalist datalist 元素规定输入域的选项列表. 列表是通过 datalist 内的 option 元素创建的. 如需把 datalist 绑定到输入域,请用输入域的 list 属性 ...
- 调整linux的时钟
想把linux时钟调整的正常了. 网上找了找资料,找到了同步办法: http://blog.51yip.com/server/1474.html 即使用: sudo yum install ntp s ...