teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

追加

2022/03/19 01:40

投稿

oika77
oika77

スコア184

title CHANGED
File without changes
body CHANGED
@@ -1,3 +1,6 @@
1
+ やりたいことは、表の1行を一つのボタンにしたいと考えています。以下の方法を自分なりに考えましたが、全く別の方法がありましたら、教えてください。よろしくお願いいたします。
2
+
3
+
1
4
  試したこととしては、
2
5
  一つ目
3
6
  hrefの値を取ってきて、そのurlに```window.location.href```で遷移するというやり方です。[参考サイト](https://uxmilk.jp/41457)

2

コードの修正

2022/03/19 01:11

投稿

oika77
oika77

スコア184

title CHANGED
File without changes
body CHANGED
@@ -41,11 +41,11 @@
41
41
  <tbody>
42
42
  <!-- 本の一覧を表示 -->
43
43
  {% for book in bookT %}
44
- {% if book.bookFlag == 0 %}
45
44
  <tr class="book_title_tr">
46
45
  <th scope="row"><a href="{% url 'book_title' bookT_page_Flag=1 bookID=book.bookID %}">{{book.bookTitle}}</a></th>
47
46
  <td>{{ book.bookDate }}</td>
48
47
  </tr>
48
+ {% endfor %}
49
49
  </tbody>
50
50
  </table>
51
51
 

1

追記

2022/03/19 01:09

投稿

oika77
oika77

スコア184

title CHANGED
File without changes
body CHANGED
@@ -20,4 +20,47 @@
20
20
  ```js
21
21
  コード
22
22
  $('.book_title_tr').children('th').children('a').trigger('click');
23
- ```
23
+ ```
24
+
25
+ 追記
26
+ ---
27
+ すみません。上の書き方だと良くなかったです。もう一度下に書き直しました。
28
+
29
+ もう全体を以下に示します。
30
+ console.logがたくさん出力されてしまいます。
31
+ ```html
32
+ コード
33
+ <table class="table book_table">
34
+
35
+ <thead>
36
+ <tr>
37
+ <th scope="col">本のタイトル</th>
38
+ <th scope="col">発行日</th>
39
+ </tr>
40
+ </thead>
41
+ <tbody>
42
+ <!-- 本の一覧を表示 -->
43
+ {% for book in bookT %}
44
+ {% if book.bookFlag == 0 %}
45
+ <tr class="book_title_tr">
46
+ <th scope="row"><a href="{% url 'book_title' bookT_page_Flag=1 bookID=book.bookID %}">{{book.bookTitle}}</a></th>
47
+ <td>{{ book.bookDate }}</td>
48
+ </tr>
49
+ </tbody>
50
+ </table>
51
+
52
+
53
+ <script>
54
+ //-------------book_title.html---------
55
+ $(function () {
56
+ $('.book_title_tr').on('click', function(){
57
+ var i = $('.book_title_tr').index(this);
58
+ console.log($('.book_title_tr').eq(i).children('th').children('a'));
59
+ $('.book_title_tr').find('th a').eq(i).click();
60
+
61
+ });
62
+ });
63
+ </script>
64
+ ```
65
+
66
+