URLエンコード/デコード、HTMLエンティティエンコード/デコードを行うとき便利なフォームを作成しました。 PHP+jQueryで実装されており、このファイルをPHPの動くWebサーバーに置けばすぐに使えます。
できること
- URLエンコード/デコード
- HTMLエンティティエンコード/デコード
- PHPの配列のシリアライズ/アンシリアライズ
必要な環境
- PHPの動作するWebサーバー
LightBoxのように、リンクをクリックするとアクションが発生するスクリプトは数多く存在します。 任意の場所をクリックした時にそのアクションを起動したい場合は、jQueryのclick()メソッドを使うと簡単に実現できます。
classが”uso”のaリンクをクリックした時に “a#mojamoja” をクリックした時のアクション起動したい場合は、下記のように書けます。
$(function() {
$("a.uso").click(function(e) {
e.preventDefault();
$("a#mojamoja").eq(0).click();
});
});
FirebugやChromeのスクリプト入力ボックスに下記のコードを書き込むと、button#usoを永遠に毎秒10回叩き続けます。
setInterval(function() {$("button#uso").eq(0).click();}, 100);
「どうしてもボタンが連打したい。でも指が折れて動かせない…。」という名人にお勧めです。
JavaScriptにおいて、「<」「>」は基本的にダメ文字(使用不可)だが、jQueryのセレクタ内で使用すると選択できたりできなかったりすることがある。
そもそも、XHTMLの仕様では「<」「>」は属性値に使ってはいけない。
たまに仕様で許可されてない記号も使えるが、そうしたものが選択できるのはブラウザ依存の偶然でしかない。
こういう文字を使うときは、別の文字に置換でもしないとダメ。例えばDOMロード後に全角の「<」「>」に置換するとか。
Selector problem: $('#\<foo') and $('#bar\>') works, but $('#\<buz\>') doesn't. – jQuery Forum
/*
* 画像の実際のサイズを取得する
*
* @param string image img要素
*/
function getActualDimension(image) {
var run, mem, w, h, key = "actual";
// for Firefox, Safari, Google Chrome
if ("naturalWidth" in image) {
return {width: image.naturalWidth, height: image.naturalHeight};
}
if ("src" in image) { // HTMLImageElement
if (image[key] && image[key].src === image.src) {return image[key];}
if (document.uniqueID) { // for IE
w = $(image).css("width");
h = $(image).css("height");
} else { // for Opera and Other
mem = {w: image.width, h: image.height}; // keep current style
$(this).removeAttr("width").removeAttr("height").css({width:"", height:""}); // Remove attributes in case img-element has set width and height (for webkit browsers)
w = image.width;
h = image.height;
image.width = mem.w; // restore
image.height = mem.h;
}
return image[key] = {width: w, height: h, src: image.src}; // bond
}
// HTMLCanvasElement
return {width: image.width, height: image.height};
}
最近のコメント