JQuery читать данные-атрибуты, скрыть / показать правильный div - PullRequest
2 голосов
/ 16 октября 2011

Я пытаюсь создать таблицу с атрибутами данных в строках и возможностью показа элементов с одинаковым атрибутом данных при нажатии. Я мог бы добавить больше атрибутов данных, если это сделает функции jquery проще / умнее.

Нужна помощь, чтобы все было хорошо играть:)

Заранее спасибо!

РЕДАКТИРОВАТЬ: jsFiddle ссылка: http://jsfiddle.net/MXpnQ/

$(".productRow").click(function () {
 $(this).parent().hide("slow"); //hides the fundListContainer
 --function to show the correct fundInfoContainer--?
});

$(".backToCorrectListButton").click(function () {
 --function to hide the fundInfoContainer and show the correct fundListContainer--?
});

<div class="fundListContainer">
<table>
 <tr class="productRow" data-fundId="1">
  <td></td>
  <td></td>
 </tr>
 <tr class="productRow" data-fundId="2">
  <td></td>
  <td></td>
 </tr>
</table>
</div>

<div class="fundInfoContainer" data-fundId="1" style="display: none">
 <div class="backToCorrectListButton">back to list</div>
</div>

<div class="fundInfoContainer" data-fundId="2" style="display: none">
 <div class="backToCorrectListButton">back to list</div>
</div>

1 Ответ

3 голосов
/ 16 октября 2011

Конечно, вы можете!

$(".productRow").click(function () {
   $(this).parent().hide("slow"); //hides the fundListContainer
   $("[data-fundId="+$(this).data('fundId')+"]").hide();
});

Если вы хотите выбрать элемент по любому из его атрибутов (data-attr или нет), используйте обозначение

$("[attr_name=value]")

См. http://api.jquery.com/attribute-equals-selector/

РЕДАКТИРОВАТЬ: Смотри, если это то, что вы хотите

http://jsfiddle.net/MXpnQ/3/

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...