Created
December 30, 2012 05:57
-
-
Save juner/4411209 to your computer and use it in GitHub Desktop.
よくやるテスト用メソッド[jQuery版]
This file contains 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
jQueryを取得している際にコーディング時に設定するスクリプトでも。 | |
test オプジェクトにテストの表示とクリアを設定します。 | |
表示する際は下記の様にします。 | |
test.print(text); | |
表示を消去する場合は下記の様にします。 | |
test.clear(); |
This file contains 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
body { background-color: #DDDDDD; font: 30px sans-serif; } |
This file contains 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
<div id="output"> | |
</div> |
This file contains 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
//簡易表示用オブジェクト test; | |
// | |
//機能 | |
// | |
// test.println(text); | |
// @param text 表示用のテキスト | |
// 予め設定しておいた要素に文字列を追加する。 | |
// | |
// test.clear(); | |
// 予め設定しておいた要素を空にする。 | |
// | |
var test = function($,outputSelecter){ | |
var output = null; | |
$(document).ready(function(){ | |
output = $(outputSelecter); | |
}); | |
return { | |
"print":function(_text){ | |
if(output instanceof jQuery) $("<div/>").text(_text).appendTo(output); | |
}, | |
"clear":function(){ | |
if(output instanceof jQuery) output.text(""); | |
} | |
}; | |
}(jQuery,"#output"); | |
//出力例 | |
(function($){ | |
var start =1; | |
var counter =start; | |
var end =10; | |
var key = setInterval(function(){ | |
if(counter>end){ | |
//クリア | |
test.clear(); | |
counter =start; | |
}else{ | |
//表示 | |
test.print("test"+counter); | |
counter++; | |
} | |
},1000); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment