|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#16
|
|||
|
|||
|
I changed it so it should be good for both IE and etc:
Code:
//orig code
var t = document.getElementById("setbut");
t.value = "Set Pieces";
t.onclick=null;
if (window.addEventListener) { // Mozilla, Netscape, Firefox
t.addEventListener('click', startGame, false);
}
else { // IE
t.attachEvent('onClick', startGame);
}
//end of orig
//now I move this code into a loop for the cells I need changing
//new code
t = document.getElementById(i+tmpA[bn]+ii);
t.onclick=null;
if (window.addEventListener) { // Mozilla, Netscape, Firefox
//changed some stuff in the line below:
t.addEventListener('click', function() { bombard(i+tmpA[bn]+ii); }, false);
if(i==10 && ii==10) alert(t.click); ;
}
else {
//your old code img.attachEvent('onClick', bombard);
//replaced with:
img.onclick= function(){bombard(i+tmpA[bn]+ii)}
}
//end new code
__________________
Sir, a desire of knowledge is the natural feeling of mankind; and every human being, whose mind is not debauched, will be willing to give all that he has to get knowledge. |
|
#17
|
|||
|
|||
|
its reasons like this that I love using jquery for handling javascript stuff.
Code:
<html>
<head>
<title>This is a test</title>
<style type="text/css">
#testTable { border-right: 1px solid black; border-bottom: 1px solid black; border-collapse: collapse; }
#testTable td { padding: 3px; border-top: 1px solid black; border-left: 1px solid black; }
#testTable td.selectedCell { background-color: #0099FF; }
#testTable td.selectedRow { background-color: #99CCFF; }
</style>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#testTable td').click(function(e){
alert(e.target.id);
$('#testTable td').removeClass('selectedCell').removeClass('sele ctedRow');
$(e.target).addClass('selectedCell').siblings().ad dClass('selectedRow');
});
});
</script>
</head>
<body>
<table id="testTable">
<tr id='row1'>
<td id='cell1_1'>Cell 1-1</td>
<td id='cell1_2'>Cell 1-2</td>
<td id='cell1_3'>Cell 1-3</td>
<td id='cell1_4'>Cell 1-4</td>
<td id='cell1_5'>Cell 1-5</td>
</tr>
<tr id='row2'>
<td id='cell2_1'>Cell 2-1</td>
<td id='cell2_2'>Cell 2-2</td>
<td id='cell2_3'>Cell 2-3</td>
<td id='cell2_4'>Cell 2-4</td>
<td id='cell2_5'>Cell 2-5</td>
</tr>
<tr id='row3'>
<td id='cell3_1'>cell 3-1</td>
<td id='cell3_2'>cell 3-2</td>
<td id='cell3_3'>cell 3-3</td>
<td id='cell3_4'>cell 3-4</td>
<td id='cell3_5'>cell 3-5</td>
</tr>
<tr id='row4'>
<td id='cell4_1'>cell 4-1</td>
<td id='cell4_2'>cell 4-2</td>
<td id='cell4_3'>cell 4-3</td>
<td id='cell4_4'>cell 4-4</td>
<td id='cell4_5'>cell 4-5</td>
</tr>
<tr id='row5'>
<td id='cell5_1'>cell 5-1</td>
<td id='cell5_2'>cell 5-2</td>
<td id='cell5_3'>cell 5-3</td>
<td id='cell5_4'>cell 5-4</td>
<td id='cell5_5'>cell 5-5</td>
</tr>
</table>
</body>
</html>
Seriously, it makes it much easier once you get the hang of it. I REALLY suggest it and also suggest you get a book about jquery and learn it. |
|
#18
|
|||
|
|||
|
Sorry, only had access to the script at work, so not been able to test it
Still not working, although I have just realised that it is redundant now, as the cells I need this applying to don't need the thiscell() in the first place, so when I write the table all I need to do is put the bombard() in the onclick and just check that the status of the script is in the correct place and do the rest of the function there. This is what happens when you spend 7 hours straight staring at code, your brain frazzles and simple connections like that aren't made >.<
__________________
~~==~~ Whoever said nothing is impossible never tried pushing a revolving door ~~==~~ |
|
#19
|
|||
|
|||
|
Oh! Thank you so much for the post. It's really useful.
Good post. I appreciate it |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > AddEventListener |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|