Last active
December 21, 2015 16:09
-
-
Save sakadonohito/6331764 to your computer and use it in GitHub Desktop.
jQueryを中心にJavaScriptメモ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //配列を作成する | |
| var width_arr = new Array(); | |
| //jQueryで階層指定及び最初の要素を指定する | |
| //下の例だと、id=estimateList配下のtbody配下の最初のtr配下のtd全て | |
| var tbody_tds = $('#estimateList tbody tr:first-child td'); | |
| //jQueryで繰り返し処理 | |
| $.each($(tbody_tds),function(i){ | |
| width_arr.push($(this).width()); | |
| }); | |
| //documentが読み込まれたら指定の関数を呼び出す | |
| $(document).ready(function(){ | |
| //function(); | |
| }); | |
| //windowのサイズが変わったら指定の関数を呼び出す | |
| $(window).resize(function(){ | |
| //function(); | |
| }); | |
| //クリックされた要素の近隣の要素を取得したり | |
| var tr = $(this).closest("tr");//td要素をクリックされた時にその親要素のtrを取得する | |
| var td1 = tr.children('td:eq(0)');//取得したtr配下の最初のtd子要素を取得 | |
| //要素が存在するかどうかチェック | |
| if($('#selectList').find('p').length){ | |
| alert("error!"); | |
| return false; | |
| } | |
| //属性値の設定 | |
| $('<form>').attr('action','url'); | |
| //指定要素の配下要素をごっそり消す | |
| $('#youso').empty(); | |
| //再描画(再読み込み) | |
| location.reload(); | |
| //要素追加 | |
| $('追加要素').appendTo($('追加先要素')); | |
| //IEの時、appendToの引数を要素objectだと失敗する。$()で囲まないと駄目。なんで? | |
| //属性を消したい時(例:checked) | |
| $('要素').removeAttr('checked'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment