Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 15.03.2018, 12:30
Новичок на форуме
Отправить личное сообщение для drakon4860 Посмотреть профиль Найти все сообщения от drakon4860
 
Регистрация: 15.03.2018
Сообщений: 5

Помогите пожалуйста
Добрый день, у меня такая проблема создал таблицу в которой можно добавлять столбцы и строки, а как теперь сделать так что бы при наведении на строку появлялась кнопка удаления этой строки и кнопка удаления столбца. Помогите пожалуйста!
Изображения:
Тип файла: jpg imgpsh_fullsize.jpg (124.4 Кб, 20 просмотров)

Последний раз редактировалось drakon4860, 15.03.2018 в 12:58.
Ответить с цитированием
  #2 (permalink)  
Старый 15.03.2018, 12:49
Профессор
Отправить личное сообщение для Rise Посмотреть профиль Найти все сообщения от Rise
 
Регистрация: 07.11.2013
Сообщений: 4,664

Перезалей картинку в jpg.
Ответить с цитированием
  #3 (permalink)  
Старый 15.03.2018, 15:20
Новичок на форуме
Отправить личное сообщение для drakon4860 Посмотреть профиль Найти все сообщения от drakon4860
 
Регистрация: 15.03.2018
Сообщений: 5

перезалил
Ответить с цитированием
  #4 (permalink)  
Старый 15.03.2018, 16:00
Аватар для ksa
ksa ksa вне форума
CacheVar
Отправить личное сообщение для ksa Посмотреть профиль Найти все сообщения от ksa
 
Регистрация: 19.08.2010
Сообщений: 14,137

Судя по картинке это какое-то тестовое задание, которое ты сам сделать не в состоянии.

Даже тестовый пример не сделал, а тупо показал картинку с самим заданием.
Ответить с цитированием
  #5 (permalink)  
Старый 15.03.2018, 16:04
Аватар для ksa
ksa ksa вне форума
CacheVar
Отправить личное сообщение для ksa Посмотреть профиль Найти все сообщения от ksa
 
Регистрация: 19.08.2010
Сообщений: 14,137

Сообщение от drakon4860
а как теперь сделать так что бы при наведении на строку появлялась кнопка удаления этой строки и кнопка удаления столбца.
Как вариант:
- поместить таблицу в некоего родителя
- при наведении вычислять координаты ячейки относительно этого родителя
- показывать, абсолютно позиционированные квадраты, с вычеслеными
координатами ячейки.
Ответить с цитированием
  #6 (permalink)  
Старый 15.03.2018, 16:10
Новичок на форуме
Отправить личное сообщение для drakon4860 Посмотреть профиль Найти все сообщения от drakon4860
 
Регистрация: 15.03.2018
Сообщений: 5

Объяснил блин!
Ответить с цитированием
  #7 (permalink)  
Старый 15.03.2018, 16:21
Новичок на форуме
Отправить личное сообщение для drakon4860 Посмотреть профиль Найти все сообщения от drakon4860
 
Регистрация: 15.03.2018
Сообщений: 5

Вот что у меня получилось не могу разобраться с удалением!

<html>
<head>
	<title>  </title>
	<script language="JavaScript">
		function add2() {
			var trArr = table.getElementsByTagName('tr');
			for (var i = 0, l = trArr.length; i < l; i++)
				var newCell = trArr[i].insertCell(0);
			newCell.width = 42;
			newCell.height = 42;
		}
		function add1() {
			var row = table.insertRow();
			var colCount = table.rows[0].cells.length;

			for (i = 0; i < colCount; i++)

				var cell = row.insertCell();

			cell.height = 50;
			cell.width = 42;
	
		}

	</script>
</head>
<body>
	<div>
		<style>
			table {
				background: white;
				color: white;
				border: 1px solid DodgerBlue;
				margin-top: 20%;
				margin-left: 45%;
			}

			td, tr {
				background: DodgerBlue;
				padding: 5px;
			}
		</style>
	</div>
	<br>
	<div>
		<table id="table" border="1">
			<tr>
				<th width="50px" height="50px" ></th>
				<th width="50px" height="50px" ></th>
				<th width="50px" height="50px" ></th>
				<th width="50px" height="50px" ></th>
			</tr>
			<tr>
				<th width="50px" height="50px"></th>
				<th width="50px" height="50px"></th>
				<th width="50px" height="50px"></th>
				<th width="50px" height="50px"></th>
			</tr>
			<tr>
				<th width="50px" height="50px"></th>
				<th width="50px" height="50px"></th>
				<th width="50px" height="50px"></th>
				<th width="50px" height="50px"></th>
			</tr>
			<tr>
				<th width="50px" height="50px"></th>
				<th width="50px" height="50px"></th>
				<th width="50px" height="50px"></th>
				<th width="50px" height="50px"></th>
			</tr>
		</table>
	</div>
	<form>
		<p><input type="button" class="b1" value="+" onclick="add1()"></p>
		<style>
			.b1 {
				width: 50px;
				height: 50px;
				background: Orange;
				border: 0px solid Orange;
				color: white;
				font-size: 25pt;
				margin-top: -1%;
				margin-left: 45%;
				cursor: pointer;
			}
		</style>
	</form>
	<form>
		<p><input type="button" class="b4" value="+" onclick="add2()"></p>
		<style>
			.b4 {
				width: 50px;
				height: 50px;
				background: Orange;
				border: 0px solid Orange;
				color: white;
				font-size: 25pt;
				margin-top: -19.4%;
				margin-left: 41.4%;
				cursor: pointer;
			}
		</style>
	</form>
</body>
</html>

Последний раз редактировалось drakon4860, 15.03.2018 в 16:24.
Ответить с цитированием
  #8 (permalink)  
Старый 15.03.2018, 19:23
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,081

добавление удаление строк и столбцов в таблицу на js
drakon4860,
<html>
<head>
  <title>  </title>
  <script>
function add2() {
  var trArr = table.getElementsByTagName("tr");
  for (var i = 0, l = trArr.length; i < l; i++) {
    var newCell = trArr[i].insertCell(0);
  }
  newCell.width = 42;
  newCell.height = 42;
}
function add1() {
  var row = table.insertRow();
  var colCount = table.rows[0].cells.length;
  for (i = 0; i < colCount; i++) {
    var cell = row.insertCell();
  }
  cell.height = 50;
  cell.width = 42;
}
window.addEventListener("DOMContentLoaded", function() {
  var table = document.querySelector("table");
  var btn = document.querySelectorAll(".btn");
  var timer;
  table.addEventListener("mousemove", function(event) {
    var el = event.target;
    if (el.tagName == "TH" || el.tagName == "TD") {
      window.clearTimeout(timer);
      var x = el.cellIndex;
      var tr = el.parentNode;
      var pos = tr.getBoundingClientRect();
      btn[0].style.left = pos.left - 60 + "px";
      btn[0].style.top = pos.top - 8 + "px";
      var y = tr.rowIndex;
      btn[1].style.left = pos.left - 4 + x * 56 + "px";
      btn[1].style.top = pos.top - 10 - (y + 1) * 52 + "px";
      btn[0].dataset.row = y;
      btn[1].dataset.cell = x;
      document.body.classList.remove("hideBtn");
    }
  });
  table.addEventListener("mouseleave", function(event) {
    window.clearTimeout(timer);
    timer = window.setTimeout(function() {
      document.body.classList.add("hideBtn");
    }, 3000);
  });
  btn[0].addEventListener("click", function(event) {
    var index = this.dataset.row;
    var tr = table.querySelectorAll("tr");
    console.log(index);
    if (tr[index] && tr.length > 1) {
      tr[index].parentNode.removeChild(tr[index]);
    }
    document.body.classList.add("hideBtn");
  });
  btn[1].addEventListener("click", function(event) {
    var index = this.dataset.cell;
    var tr = table.querySelectorAll("tr");
    [].forEach.call(tr, function(el) {
      console.log(index);
      if (el.cells[index] && el.cells.length > 1) {
        el.removeChild(el.cells[index]);
      }
    });
    document.body.classList.add("hideBtn");
  });
});
  </script>
</head>
<body class="hideBtn">
  <div>
    <style>
      table {
        background: white;
        color: white;
        border: 1px solid DodgerBlue;
        margin-top: 20%;
        margin-left: 45%;
      }

      td, tr {
        background: DodgerBlue;
        padding: 5px;
      }
      body {
        position:  relative;
      }

      .btn {
        position:  absolute;
        background-color:  #B20000;
        height: 50px;
        width: 50px;
        color: #FFFFFF;
        text-align: center;
        line-height: 40px;
        font-size: 25pt;
      }
      body.hideBtn .btn{
        display: none;
      }

    </style>
  </div>
  <br>
  <div>
    <table id="table" border="1">
      <tr>
        <th width="50px" height="50px" ></th>
        <th width="50px" height="50px" ></th>
        <th width="50px" height="50px" ></th>
        <th width="50px" height="50px" ></th>
      </tr>
      <tr>
        <th width="50px" height="50px"></th>
        <th width="50px" height="50px"></th>
        <th width="50px" height="50px"></th>
        <th width="50px" height="50px"></th>
      </tr>
      <tr>
        <th width="50px" height="50px"></th>
        <th width="50px" height="50px"></th>
        <th width="50px" height="50px"></th>
        <th width="50px" height="50px"></th>
      </tr>
      <tr>
        <th width="50px" height="50px"></th>
        <th width="50px" height="50px"></th>
        <th width="50px" height="50px"></th>
        <th width="50px" height="50px"></th>
      </tr>
    </table>
  </div>
  <div class="btn">-</div>
  <div class="btn">-</div>
  <form>
    <p><input type="button" class="b1" value="+" onclick="add1()"></p>
    <style>
      .b1 {
        width: 50px;
        height: 50px;
        background: Orange;
        border: 0px solid Orange;
        color: white;
        font-size: 25pt;
        margin-top: -1%;
        margin-left: 45%;
        cursor: pointer;
      }
    </style>
  </form>
  <form>
    <p><input type="button" class="b4" value="+" onclick="add2()"></p>
    <style>
      .b4 {
        width: 50px;
        height: 50px;
        background: Orange;
        border: 0px solid Orange;
        color: white;
        font-size: 25pt;
        margin-top: -19.4%;
        margin-left: 41.4%;
        cursor: pointer;
      }
    </style>
  </form>
</body>
</html>
Ответить с цитированием
  #9 (permalink)  
Старый 17.03.2018, 18:15
Новичок на форуме
Отправить личное сообщение для drakon4860 Посмотреть профиль Найти все сообщения от drakon4860
 
Регистрация: 15.03.2018
Сообщений: 5

Спасибо огромное!
Ответить с цитированием
Ответ



Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Помогите пожалуйста!!! igrovik Общие вопросы Javascript 40 10.04.2018 13:53
Пожалуйста помогите сделать проверку выполнения vk Dodik Общие вопросы Javascript 3 01.03.2013 16:49
Помогите пожалуйста разобраться со скриптом Shalty Opera, Safari и др. 1 21.01.2013 16:41
Пожалуйста помогите решить задачу на java alex01rus1991 Элементы интерфейса 9 27.11.2012 01:02
Помогите, пожалуйста! rzhsasha Ваши сайты и скрипты 2 20.07.2009 21:07