{js} 論理演算子「&&」の練習。

段々演算子の全体が見えてきた。
スイッチをクリックでスクリプト実行。この演算子の重要度がやっとわかった。
<script>

function hogehoge(){

a = 1;
b = 2;
c = 3;

	if(a == 1 && b == 2 && c == 3){
		alert("true");
	}else{
		alert("false");
	}

}



</script>
<button onclick="hogehoge()">スイッチ</button>

応用。

<script>
jQuery(function(){

	$("#switch").click(function(){
		a = $(".wrap input:eq(0)").val();
		b = $(".wrap input:eq(1)").val();
		c = $(".wrap input:eq(2)").val();	

		if(a == 1 && b == 1 && c == 1){
			alert("3つとも「1」。");
		}else{
			alert("「3つとも「1」」じゃない。");
		}
	});
})

</script>
<div class="wrap">
<input type="text" value="1">
<input type="text" value="2">
<input type="text" value="3">
</div>
<button id="switch">switch</button>

カテゴリ:

トラックバック(0)

トラックバックURL: http://www.0yen-coding.com/mt-tb.cgi/261

コメントする

あわせて読みたいブログパーツ