ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文
jQuery の .val(関数) を使用した、社員コードに対する明細データの表示サンプル
日時: 2011/07/22 19:17
名前: lightbox




社員コード 氏名 年齢 生年月日
拡張子:
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
社員コード <input class="action1" type="text" />
<input type="button" value="実行" onclick='action1();'>
<br />
氏名 <input class="action2" type="text" /><br />
年齢 <input class="action2" type="text" /><br />
生年月日 <input class="action2" type="text" /><br />

<script type="text/javascript">
var target = {
	'0001' : ['山田 太郎',20,'1991/05/01'],
	'0002' : ['山田 次郎',21,'1990/06/10'],
	'0003' : ['鈴木 花子',22,'1989/07/25']
};

// 入力された社員コードに対する値を target から取得
function setVals( index, value ) {

	var scode = $('input.action1').val();

	if ( target[scode] ) {
		return( target[scode][index] );
	}
	else {
		return( '' );
	}
}

// 入力された社員コードからテータを取りだす
function action1() {

	// action2 クラスに対して全て処理
	$('input.action2').val(setVals);

}
</script>
メンテナンス


日時: 2011/07/22 19:17
名前: lightbox