2013年8月28日水曜日

jQueryで、子要素親要素、IDの値の取得など。

要素をjQueryで走査し、見つかった要素のIDの値を取得したい場合、以下のよう。

var idname = $(this).attr("id");

その親要素にのぼって、自分と同列の子要素で別クラス名の値を取得したい場合、以下のよう。

var classname=$(this).parent().children(".classname");

modalを使いたかったので探してみた。

modalウインドウを表示させ、
form処理などをしたくて、jQueryのプラグインを物色。

以下のものが良かったので、使い始めました。
simplemodal
http://www.ericmmartin.com/projects/simplemodal/

css でdisplay:nonに設定して、
表示させたい要素に .modal() を加えると。

シンプル。

2013年7月20日土曜日

getJSONは、JSON以外の文字列を表示させてはダメのようで。

jQueryでgetJSONをPHPとの連携で使ったとき、
PHP側でJSON以外の文字列を出力すると、全く反応しないと判明。

なぜか反応しないので,原因を調べていて,判明。
JSON以外の文字列をvar_dumpなどで表示させていたのが問題でした。

気をつけるべし。

2013年4月7日日曜日

google spreadsheetに秒数計算関数

google spreadsheetにUNIX秒を挿入したかったので、取り組み。

以下のページの記述が役に立った。google spreadsheetでは、script editorでjsコードを書けて、それをspreadsheet上で関数を実行できることを改めて再認識。
http://productforums.google.com/forum/#!topic/docs/rPf3kgv6OZU
To create a "timestamp" formula, you can write your own custom timestamp() function and then have it update based on when the contents of another cell are modified.
1. Tools > Scripts > Script Editor2. Paste the following code:
function timestamp() {
return new Date()
}
3. Save and go back to your Spreadsheet
Let's say you want a timestamp in cell B1 whenever cell A1 is updated...
In cell B1 put the forumla =TIMESTAMP(A1)
*** However, this will show a timestamp even if cell A1 is blank.  To only show a timestamp when a cell has content, use this formula:
=IF(ISBLANK(A1),,TIMESTAMP(A1))
Hope this helps! 
で、自分が書いたスクリプトが以下。
function timestamp(a,b,c ,d) { var now=new Date(a,b,c,d); var time=now.getTime(); return time }
年月日時間の四要素から、秒を取得する必要があったので、上記のような感じで。

便利なり、google spreadsheet !

2013年4月5日金曜日

innerHTMLはonload後の処理


innerHTMLを使ってみたら、適用されないので、不思議に思い、
調べたら、
onloadされた後に適用される、と分かった。
onloadされた後の処理に突っ込まないと適用されないinnerHTML。
理解しました。