实用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 ...
随机推荐
- 学SEO你其实只需要半个钟
网站上线之前: 关键词的分析以及选择: 关键词在我们网站的每个页面:首页,栏目页,文章都存在,它定位了你的网站的这个页面是做什么的,有什么内容,也是SEO中的最重要的部分. 网站必须确定并且设置好关键 ...
- poj 1088 dp **
链接:点我 记忆化搜索很好写 #include<cstdio> #include<iostream> #include<algorithm> #include< ...
- hdu 4622 **
题意:Suppose there are the symbols M, I, and U which can be combined to produce strings of symbols cal ...
- Spring的profile属性
使用示例 //注解方式 public class DataSourceConfig { @Bean @Profile("prod") public DataSource dataS ...
- SU Demos 03T-F Analysis-03Suphasevel
不足之处,欢迎批评指正. 1.先看readme,共有3个脚本. 第1个脚本用到的模型文件. 2.第1个脚本 运行结果 3.第2个脚本 4.第3个脚本
- http://love3400wind.blog.163.com/blog/static/7963080120132794359703/
http://love3400wind.blog.163.com/blog/static/7963080120132794359703/
- Storm Grouping —— 流分组策略
Storm Grouping: Shuffle Grouping :随机分组,尽量均匀分布到下游Bolt中 将流分组定义为混排.这种混排分组意味着来自Spout的输入将混排,或随机分发给此Bolt中的 ...
- [leetCode][016] Add Two Numbers
[题目]: You are given two linked lists representing two non-negative numbers. The digits are stored in ...
- TYVJ P1026 犁田机器人 Label:水
背景 USACO OCT 09 2ND 描述 Farmer John為了让自己从无穷无尽的犁田工作中解放出来,於是买了个新机器人帮助他犁田.这个机器人可以完成犁田的任务,可惜有一个小小的缺点:这个犁田 ...
- 【BZOJ】2178: 圆的面积并
http://www.lydsy.com/JudgeOnline/problem.php?id=2178 题意:给出n<=1000个圆,求这些圆的面积并 #include <cstdio& ...