Created
January 9, 2013 03:26
-
-
Save shoyan/4490318 to your computer and use it in GitHub Desktop.
カスタムオブジェクトのサンプル
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
<script> | |
var Obj = function(){ | |
var background = "#fff"; | |
var state = "on"; | |
this.change_state = function(){ | |
if(state === "on"){ | |
state = "off"; | |
background = "#000"; | |
} else { | |
state = "on"; | |
background = "#fff"; | |
} | |
} | |
this.get_color = function(){ | |
return background; | |
} | |
this.get_state = function(){ | |
return state; | |
} | |
} | |
var obj = new Obj(); | |
function clicked(){ | |
obj.change_state(); | |
$('#d1').attr('style', "background-color:" + obj.get_color()); | |
$('#d0').text("状態:" + obj.get_state() + " 背景色: " + obj.get_color()); | |
} | |
</script> | |
<input type="button" value="背景色を変更" onclick="clicked()" /> | |
<br /> | |
<div id="d0" style="background-color:white !important;"> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment