JavaScript

cssで画面中央へ常に表示する

LightBoxっぽい感じで。prototype.js,jQuery使ってません。IE6無理 そのたの主要ブラウザ(chrome,Fx,IE7+8,Opera,Safari,Lunascape)はOK div#certification { position: fixed!important; position: absolute; top:0; left:0; width:100%; height:100%; z-in…

入力補助

編集中 addEditToolButton(document.getElementById("ttttt")); function addEditToolButton(textarea) { var toolbar = document.createElement("div"); function addButton(id, title, fn) { var a = document.createElement("div"); a.href = "#"; a.inne…

外部サイト判定?

"http://juice.com".match(/https?:\/\/([^\.]*\.?juice\.com)/); link_Href.search(/([a-z0-9]*\.ABCDE|^ABCDE)\.com/); "juice.com".match(/^[^\.]*\.?juice\.com/i); "juice.com".match(/^[^\.]*\.juice\.com/i); "juice.com".search(/^([^\.]*\.)?juice\…

.searchと.match

"http://ABCDE.com/".search(/^http:\/\/[0-9a-z]*.?ABCDE\.com/i);searchは検索位置を返します。ない場合は-1 "http://ABCDE.com/".match(/^http:\/\/[0-9a-z]*.?ABCDE\.com/i);matchは一致した文字列を返します。ない場合はnullです "<th>aisdiuauaa</th>".match(/<th>(</th>…

jsでphpとおなじ動作のtrim

strSrc = strSrc.replace(/(^[ \r\n\t]+)|([ \r\n\t]+$)/g, "");

javascriptでphpと同様のtrimする

phpは全角スペースはtrimしない str = str.replace(/(^[ \r\n\t]+)|([ \r\n\t]+$)/g, ""); <|| 全角スペースもtrim >|js| str = str.replace(/(^[\s]+)|([\s]+$)/g, "");

(memo)Javascript 正規表現

http://www.tohoho-web.com/js/regexp.htm "12:34:56".match(/(\d+):(\d+):(\d+)/); document.write(RegExp.$1 + "<br>"); // → 12 document.write(RegExp.$2 + "<br>"); // → 34 document.write(RegExp.$3 + "<br>"); // → 56RegExpが定義されていないような感じだけど…

(memo)DOMとか

querySelector や querySelectorAll http://d.hatena.ne.jp/amachang/20080306/1204787459 document.querySelectorAll("タグ.class"); document.querySelectorAll("div.strong");とか Allは全部取得するけど、querySelectorは先頭の一つだけ取得する。 文字…

ChromeExtensionでクロスドメイン

manifest.jsonでpermissionの設定すればクロスドメインできる...!できないらしい。 http://d.hatena.ne.jp/love_firefoxportable/20091214/1260801125 background_page.htmlというファイルを作ってそこで、XMLHttpRequestして、結果を返してあげればできまし…

WebサーバとローカルのAjaxの挙動の違い

ローカルではIEでXMLを正常に取得する事が出来ない(かもしれない)。 でも、Webサーバにアップすると正常に動作する可能性がある。 FireFox,ChromeではWebサーバ,ローカル共に動くみたい。 参考 http://watcher.moe-nifty.com/memo/2007/03/ie7_xmlhttprequ_0…

AJAX で、getElementsByTagName で DOM にアクセスする

参考 ttp://perltips.twinkle.cc/ajax/dom_getelementsbytagname.php<books> <book> <title>初めての AJAX</title> <author>AJAX 編集部</author> <publisher>AJAX 社</publisher> </book> <book> <title>初めての Perl</title> <author>Perl 編集部</author> <publisher>Perl 出版</publisher> </book> <book> <title>初めての PHP</title> </book></books>

チェックボックスの値を取得する

// ○ <input type="checkbox" id="chawchaw"> var isChecked = document.getElementById("chawchaw").checked // false or true // × <input type="checkbox" id="chawchaw" value="1"> var isChecked = document.getElementById("chawchaw").value // isChecked = 1;