7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

jQueryでセルの値によって背景を変更

7
Posted at

テーブルのセルの値によって、セルの色を変更させる。
sinatraより判定式の値を受け取るため、find内は最初に宣言しておく。

index.erb
<script type="text/javascript">
var Obj_x1 = 'td.dval-x:myLG(>' + <%= @x1 %> +')';
var Obj_y1 = 'td.dval-y:myLG(>' + <%= @y2 %> +')';
var Obj_z1 = 'td.dval-z:myLG(>' + <%= @z3 %> +')';

jQuery(function($){
	$('#mainTBL')
	.find(Obj_x1).css('background','gold').end()
	.find(Obj_y1).css('background','coral').end()
	.find(Obj_z1).css('background','red').end()
	});
}

jQuery.extend(jQuery.expr[":"], {
	myLG  : function(a,i,m){ 
		var b = Number(
			(a.textContent||a.innerText||jQuery(a).text()||"")
			.replace(/,/g,'')
		);
		return typeof b=='number'? eval(b+m[3]):false;
	}
});
</script>

参照)jQueryのセレクタを自作してみる

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?