Skip to content

Instantly share code, notes, and snippets.

View hugojay's full-sized avatar
🇹🇼
Don't Forget 64 in China

宇狗 Hugo hugojay

🇹🇼
Don't Forget 64 in China
View GitHub Profile
@hugojay
hugojay / selector-tooltips-jquery.js
Last active December 14, 2015 05:48
滑鼠移至下拉式選單(<select>)之上的時候,用 tooltip 提示氣泡的方式顯示目前下拉式選單所選擇的文字內容。 使用動機:當<select>被限制寬度,而可能無法一目了然地看到目前所選擇的長文字時。 需要:jQuery 1.7以上,如為jQuery 1.4.2~1.6.x只要把.on()改成.delegate()寫法即可
$(document).ready(function(){
$("select").on("mouseenter", function(){
if($("#tooltip").length == 0){
$("body").append("<div id='tooltip'></div>");
}
$("#tooltip").text($(this).children(":selected").text());
$("#tooltip").css("position", "absolute").hide();
$(document).on("mousemove", function(e){
$("#tooltip").fadeIn("fast").css({
left: e.pageX + 9,
@hugojay
hugojay / EAN-13_UPC-A_checking.js
Last active December 14, 2015 05:48
JavsScript 國際條碼 EAN-13/UPC-A 格式檢核
function checkBarcode(code){
var result = false;
if(code.length >= 12 && code.length <= 13){
if(code.length == 12){
code = "0" + code;
}
var odd = 0,
even = 0;
for(var i in code){
if(i%2 == 0){
@hugojay
hugojay / input_disabled.css
Created May 14, 2013 07:32
因QE發現Firefox某版本中,表單項目屬性為disabled時,因頁面套了很多不知道怎麼寫的CSS(含reset.css),在其影響下會「無視」disabled應有的「反白」效果(input 的背景、文字為灰色),而呈現猶如一般表單可輸入的樣式。但在IE、Chrome上卻又有反白效果。於是乎,我寫了一段CSS來「統一」表單項目屬性為disabled的效果,讓各瀏覽器都能表達"disabled"的情形。由於IE原本就不受影響,故可恣意使用不支援的selector及屬性。
input:disabled {
/*修正input disabled樣式*/
color: #666;
background: #ddc;
text-shadow: 1px 1px #FFF;
}
// Released under MIT license: http://www.opensource.org/licenses/mit-license.php
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);