Skip to content

Instantly share code, notes, and snippets.

View caok's full-sized avatar

Clark caok

View GitHub Profile
@caok
caok / gist:9105599
Created February 20, 2014 01:58
HTML页面内容禁止选择、复制、右键
<body leftmargin=0 topmargin=0 oncontextmenu='return false' ondragstart='return false' onselectstart ='return false' onselect='document.selection.empty()' oncopy='document.selection.empty()' onbeforecopy='return false' onmouseup='document.selection.empty()'>
关键就在
oncontextmenu='return false'
ondragstart='return false'
onselectstart ='return false'
onselect='document.selection.empty()'
oncopy='document.selection.empty()'
onbeforecopy='return false'
onmouseup='document.selection.empty()'
@caok
caok / gist:9086913
Created February 19, 2014 06:14
jquery 事件冒泡
冒泡事件就是点击子节点,会向上触发父节点,祖先节点的点击事件。
下面是html代码部分:
<body>
<div id="content">
外层div元素
<span>内层span元素</span>
外层div元素
</div>
@caok
caok / gist:8877936
Created February 8, 2014 07:22
如何在Node.js中获取本机IP地址
//获取本地IP地址
var os = require('os');
var IPv4,hostName;
hostName=os.hostname();
for(var i=0;i<os.networkInterfaces().eth0.length;i++){
if(os.networkInterfaces().eth0[i].family=='IPv4'){
IPv4=os.networkInterfaces().eth0[i].address;
}
}
console.log('----------local IP: '+IPv4);
@caok
caok / gist:8643896
Created January 27, 2014 06:08
如何让元素位于DIV内的底部
<div id="a">
<ul>
<li class="b">位于底部</li>
</ul>
</div>
<style>
#a{
width:200px;
height:200px;
@caok
caok / gist:8487368
Created January 18, 2014 07:21
键盘上下键头选中div的内容
<html>
<head>
<title>SimulateUpDownKeySelect</title>
</head>
<body>
<input type="text" id="txtInput"/>
<div id="divSelect">
<li>123</li>
<li>456</li>
window.onload
必须等待网页中所有的内容加载完毕后(包括图片)才能执行
不能同时编写多个,比如:
window.onload = function() {
alert("111");
};
window.onload = function() {
alert("222");
@caok
caok / gist:8466786
Last active January 3, 2016 12:59
使用纯CSS3来生成家谱(family tree)
<!--
We will create a family tree using just CSS(3)
The markup will be simple nested lists
-->
<div class="tree">
<ul>
<li>
<a href="#">Parent</a>
<ul>
<li>
@caok
caok / haiku.rb
Last active January 2, 2016 07:19
Active Record Reputation System
-- <%= haiku.user.name %>
| <%= pluralize haiku.votes, "vote" %>
<% if current_user && current_user.can_vote_for?(haiku) %>
| <%= link_to "up", vote_haiku_path(haiku, value: 1), method: "post" %>
| <%= link_to "down", vote_haiku_path(haiku, value: -1), method: "post" %>
<% end %>
@caok
caok / format_datetime.js
Last active January 2, 2016 01:39
时间对象的格式化
Date.prototype.format = function (format) {
/*
* eg:format="YYYY-MM-dd hh:mm:ss";
*/
var o = {
"M+" : this.getMonth() + 1, // month
"d+" : this.getDate(), // day
"h+" : this.getHours(), // hour
"m+" : this.getMinutes(), // minute
"s+" : this.getSeconds(), // second
@caok
caok / gist:8108019
Created December 24, 2013 02:32
jQuery 屏蔽单个元素使用户无法点击
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
// 下面的插件部分建议放在js文件中, 方便调用
//-------------- 插件 begin ------------------
(function ($) {