|
автор: DDDima (06.07.2005 в 10:10) |
|
| Можно ли записать
onClick = if (color==ffffff) {...} else {...}
Я хочу, чтобы при щелчке на строку в таблице, эта строка выделялась другим цветом. А при втором щелчке становилась обычной. Можно ли это сделать без использования функций? | |
|
|
|
|
автор: DDDima (06.07.2005 в 10:48) |
|
|
для: DDDima
(06.07.2005 в 10:10)
| | Никто не сталкивался с этим? Может есть возможность поставить правую кнопку для выделения, а левую для снятия выделения? | |
|
|
|
|
|
|
|
для: DDDima
(06.07.2005 в 10:10)
| | если я вас правильно понял,могу предложить следующий вариант:
<html>
<head>
<style>
.css1{color:blue}
</style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td class="css1" id="myt" onmousedown="id = event.srcElement.id;if(document.getElementById(id).style.color='red') document.getElementById(id).style.color='blue';" onclick="id = event.srcElement.id;if(document.getElementById(id).style.color='blue') document.getElementById(id).style.color='red';" >your text</td>
</tr>
</table>
</body>
</html>
Только не помню как сделать на правуб кнопку,сделал просто на onmousedown.
Если вы замените onmousedown на "правую кнопку",то всё будет нормально.
|
| |
|
|
|
|
|
|
|
для: servannin
(06.07.2005 в 11:08)
| | а всё вспомнил , заменете onmousedown на OnContextMenu.
Но оно не очень удобно , так как выскакивает стандартное меню. | |
|
|
|
|
|
|
|
для: servannin
(06.07.2005 в 11:10)
| | Спасибо идея неплохая. мне нужно немного другое. Вот код
<TR STYLE = background-color:#eaeaf2 onclick = "this.style.cssText = 'background-color:#dddddd;'" onDblClick = "this.style.cssText = 'background-color:#eaeaf2;'">
<TD> </TD><TD>Bla-bla</TD><td>11111111111</td><td>example</td></TR>
|
Все очень просто :) Допустим таблица большая. Много полей. Нужно отследить 10 поле, 300-й строки, которое уже за пределами экрана. Человек выделяет необходимую строку и уже добираясь скорлингом до нужного поля спокойно идет по подсвеченной строке.... Вот так. Хотя конечно в идеале, я хочу чтобы таблица была в ifrаme, и щелкнув по нужной строкеона помещалась вдругой iframe. Вот так. | |
|
|
|
|
|
|
|
для: Maloy
(06.07.2005 в 11:34)
| | А при другом щелчке выделение бы снималось | |
|
|
|
|
|
|
|
для: Maloy
(06.07.2005 в 11:36)
| | кстати, вы может знаете ответ на мою тему "как взять id нижнего слоя щёлкнув по верхнему? а то чего-то идей не приходит
"??? | |
|
|
|
|
|
|
|
для: servannin
(06.07.2005 в 11:50)
| | Я в javascript не очень хорошо разбираюсь. Мне нужно просто хорошо оформить свой проект, я больше в РНР пишу + Oracle немного. | |
|
|
|
|
|
|
|
для: Maloy
(06.07.2005 в 11:55)
| | ну понятно, удачи вам :) | |
|
|
|
|
|
|
|
для: Maloy
(06.07.2005 в 11:34)
| | Код вытащил из phpmyadmin с небольшой адаптацией.
<html>
<head>
<script type="text/javascript" language="javascript">
<!--
var marked_row = new Array;
function setPointer(theRow)
{
var theDefaultColor = "#FFFFFF";
var thePointerColor = "#dddddd";
var theMarkColor = "#FFFF00";
var theAction = "click";
var theCells = null;
var theRowNum =1;
// 2. Gets the current row and exits if the browser can't get it
if (typeof(document.getElementsByTagName) != 'undefined') {
theCells = theRow.getElementsByTagName('td');
}
else if (typeof(theRow.cells) != 'undefined') {
theCells = theRow.cells;
}
else {
return false;
}
// 3. Gets the current color...
var rowCellsCnt = theCells.length;
var domDetect = null;
var currentColor = null;
var newColor = null;
// 3.1 ... with DOM compatible browsers except Opera that does not return
// valid values with "getAttribute"
if (typeof(window.opera) == 'undefined'
&& typeof(theCells[0].getAttribute) != 'undefined') {
currentColor = theCells[0].getAttribute('bgcolor');
domDetect = true;
}
// 3.2 ... with other browsers
else {
currentColor = theCells[0].style.backgroundColor;
domDetect = false;
} // end 3
// 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
if (currentColor.indexOf("rgb") >= 0)
{
var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
currentColor.indexOf(')'));
var rgbValues = rgbStr.split(",");
currentColor = "#";
var hexChars = "0123456789ABCDEF";
for (var i = 0; i < 3; i++)
{
var v = rgbValues[i].valueOf();
currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
}
}
// 4. Defines the new color
// 4.1 Current color is the default one
if (currentColor == ''
|| currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
if (theAction == 'over' && thePointerColor != '') {
newColor = thePointerColor;
}
else if (theAction == 'click' && theMarkColor != '') {
newColor = theMarkColor;
marked_row[theRowNum] = true;
}
}
// 4.1.2 Current color is the pointer one
else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
&& (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
if (theAction == 'out') {
newColor = theDefaultColor;
}
else if (theAction == 'click' && theMarkColor != '') {
newColor = theMarkColor;
marked_row[theRowNum] = true;
}
}
// 4.1.3 Current color is the marker one
else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
if (theAction == 'click') {
newColor = (thePointerColor != '')
? thePointerColor
: theDefaultColor;
marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
? true
: null;
}
} // end 4
// 5. Sets the new color...
if (newColor) {
var c = null;
// 5.1 ... with DOM compatible browsers except Opera
if (domDetect) {
for (c = 0; c < rowCellsCnt; c++) {
theCells[c].setAttribute('bgcolor', newColor, 0);
} // end for
}
// 5.2 ... with other browsers
else {
for (c = 0; c < rowCellsCnt; c++) {
theCells[c].style.backgroundColor = newColor;
}
}
} // end 5
return true;
}
//-->
</script>
</head>
<body>
<table>
<tr name=1 onmousedown="setPointer(this);">
<td name=td bgcolor="#DDDDDD">Длинная... очень длинная строка</td>
<td bgcolor="#DDDDDD">11111111111111111</td>
</tr>
<tr onmousedown="setPointer(this);">
<td bgcolor="#DDDDDD">Длинная... очень длинная строка</td>
<td bgcolor="#DDDDDD">2222222222222222222</td>
</tr>
</table>
</body>
</html>
|
| |
|
|
|