memo

memo dayo.

javascript

selectのoptionを非表示にする時のメモ

■Before <select> <option id="test0" value="">▼ 選択してね!</option> <option id="test1" value="1">A</option> <option id="test2" value="2">B</option> <option id="test3" value="3">C</option> </select> ■例えばこんな感じで、hidden属性を追加 document.getElementById('test0').setAttribute('hidden','hidden'); document.getElemen…

createObjectURLの初期化

var createObjectURL = window.URL && window.URL.createObjectURL ? function (file) { return window.URL.createObjectURL (file); } : window.webkitURL && window.webkitURL.createObjectURL ? function (file) { return window.webkitURL.createObjectU…

jQueryオブジェクトをStringにする

function jq2str (obj_jq) { return $('<div>').append( obj_jq.clone() ).html();}</div>

jQueryでselectの属性と要素を取得する

function test_func (obj_slc) { var slc_name = obj_slc.id; alert( $('#' + slc_name).children(':selected').val() ); alert( $('#' + slc_name).children(':selected').text() ); } <select id="slc_0001" onchange="test_func(this);"><option value="1">aaa</option><option value="2">bbb</option></select>

jQueryで指定したidの位置までスムーズにスクロールする

// ==================================== function buta_scroll (div_id) { var int_top = 0; int_top = $('#' + div_id).offset().top; int_top = int_top - 30; $('body,html').animate({scrollTop:int_top}, 500, 'swing'); } // ======================…

jQueryでcheckboxが選択された個数を取得する

if ($('.hoge:checked').map(function(aaa, bbb) { return $(this).val(); }).length != 3){ window.alert('3つ選択して下さい'); }

jQueryで画像の縦横比率を保ったままリサイズする

jQuery.event.add(window, "load", function(){ var cst_w = 320;//fixed width var cst_h = 320;//fixed height $('img').each(function(){ var int_w = $(this).width(); var int_h = $(this).height(); if (int_w >= int_h) { $(this).width(cst_w); $(th…

配列から重複した値を削除する

■配列に新しい関数を追加する。 // ============================================== Array.prototype.uniq = function() { var obj_aaa = {}; var int_idx = 0; var int_len = this.length; var ary_rtn = [ ]; for (int_idx=0; int_idx