下記の例にて、var idxとtdsは計2回宣言されてますが、これはやはり直近のfunctionがスコープ範囲となるルールに基づいたためでしょうか?
大枠の$(function(){がスコープ範囲なるような指定方法はございますでしょうか?
varを付けなかった場合はグローバルとなりますが、$(function(){の外でも効いてしまうと理解しています。
<script> $(function(){ $("table.sample td").hover(function() { var idx = $(this).index() + 1 var tds = $(this).closest("table.sample").find("td:nth-child(" + idx + ")"); tds.css("background-color","#FFFF99"); $(this).css("background-color","#f99"); $(this).siblings().css('background', '#FFFF99'); }, function() { var idx = $(this).index() + 1 var tds = $(this).closest("table.sample").find("td:nth-child(" + idx + ")"); tds.css("background-color","#fff"); $(this).css("background-color","#fff"); $(this).siblings().css('background', '#fff'); }); }); </script>
回答2件
あなたの回答
tips
プレビュー