jsはmapを使ってidセットを取り、一行をクリックして選択します.
7231 ワード
<tbody >
<tr >
<td >1</td>
<td> <br> </td>
<td>2011-11-11</td>
<td> </td>
</tr>
<tr >
<td>2</td>
<td> <br> </td>
<td>2011-11-11</td>
<td> </td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="span7" id="right" >
<table id="table1">
<caption> </caption>
<thead>
<tr>
<td> <input type="checkbox" name="checkbox" id="btn"/> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</thead>
<tbody id="selectable">
<tr class="dragableBox" id="box1" >
<td id="45"> <input type="checkbox" name="box1" />1</td>
<td> <br> </td>
<td>2011-01-30</td>
<td> </td>
</tr>
<tr class="dragableBox" id="box2" ondragstart="test2()">
<td> <input type="checkbox" name="box2" />
2</td>
<td> <br> </td>
<td>2011-01-30</td>
<td> </td>
</tr>
<tr class="dragableBox" id="box3" ondragstart="test2()">
<td> <input type="checkbox" name="box3" />
3</td>
<td> <br> </td>
<td>2011-01-30</td>
<td> </td>
</tr>
<tr class="dragableBox" id="box4">
<td> <input type="checkbox" name="box4" />
4</td>
<td> <br> </td>
<td>2011-01-30</td>
<td> </td>
</tr>
<tr class="dragableBox" id="box5">
<td> <input type="checkbox" name="box5"/>
5</td>
<td> <br> </td>
<td>2011-01-30</td>
<td> </td>
</tr>
<tr class="dragableBox" id="box6" onclick="clickDrop()" >
<td> <input type="checkbox" name="box6" />
6</td>
<td> <br> </td>
<td>2011-01-30</td>
<td> </td>
</tr>
<tr class="dragableBox" id="box7">
<td> <input type="checkbox" name="box7" />
7</td>
<td> <br> </td>
<td>2011-01-30</td>
<td> </td>
</tr>
</tbody>
</table>
<input type="button" value="test" onclick="test2();"/>
<script type="text/javascript">
var map = new HashMap();
$(function(){
$("#table1 tr ").click(function(e){
var trId=this.id;
$("input[type='checkbox']").each(function(){// ID
if(this.name==trId){
if(this.checked==true){
$(this).attr("checked",false);
map.remove(this.name);
var dd=document.getElementById(trId);
dd.style.backgroundColor= "white";
}else{
$(this).attr("checked",true);
map.put(this.name,trId);
var dd=document.getElementById(trId);
dd.style.backgroundColor= " #FECA40";
}
}
});
});
});
</script>
function HashMap()
{
/** Map **/
var size = 0;
/** **/
var entry = new Object();
/** **/
this.put = function (key , value)
{
if(!this.containsKey(key))
{
size ++ ;
}
entry[key] = value;
}
/** **/
this.get = function (key)
{
if( this.containsKey(key) )
{
return entry[key];
}
else
{
return null;
}
}
/** **/
this.remove = function ( key )
{
if( delete entry[key] )
{
size --;
}
}
/** Key **/
this.containsKey = function ( key )
{
return (key in entry);
}
/** Value **/
this.containsValue = function ( value )
{
for(var prop in entry)
{
if(entry[prop] == value)
{
return true;
}
}
return false;
}
/** Value **/
this.values = function ()
{
var values = new Array(size);
for(var prop in entry)
{
values.push(entry[prop]);
}
return values;
}
/** Key **/
this.keys = function ()
{
var keys = new Array(size);
for(var prop in entry)
{
keys.push(prop);
}
return keys;
}
/** Map Size **/
this.size = function ()
{
return size;
}
}
// var map = new HashMap();
/*
map.put("A","1");
map.put("B","2");
map.put("A","5");
map.put("C","3");
map.put("A","4");
*/
/*
alert(map.containsKey("XX"));
alert(map.size());
alert(map.get("A"));
alert(map.get("XX"));
map.remove("A");
alert(map.size());
alert(map.get("A"));
*/
/** Key **/
/*
var arrayKey = new Array("1","2","3","4");
var arrayValue = new Array("A","B","C","D");
map.put(arrayKey,arrayValue);
var value = map.get(arrayKey);
for(var i = 0 ; i < value.length ; i++)
{
//alert(value[i]);
}
*/
/** Key , toString() String Key**/
/** toString() . **/
// function MyObject(name)
// {
// this.name = name;
// }
/**
function MyObject(name)
{
this.name = name;
this.toString = function ()
{
return this.name;
}
}
**/
// var object1 = new MyObject(" ");
// var object2 = new MyObject(" ");
//
// map.put(object1," ");
// map.put(object2," ");
// alert(map.get(object1));
// alert(map.get(object2));
// alert(map.size());
//
/** size = 1 **/
/** toString() , **/