第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

django鏈接表行查看

django鏈接表行查看

夢里花落0921 2022-07-08 18:22:36
編碼新手。我正在使用 django 框架創(chuàng)建一個庫存表。我希望能夠單擊表格行(這是一部分),然后將該行/部分信息解析為詳細信息視圖。據(jù)我了解,表格行是內(nèi)聯(lián)元素,內(nèi)聯(lián)元素是偽代碼,當(dāng)前的 HTML 不允許在其中拋出錨標(biāo)記(不好的做法?)所以我需要使用一些 javascript。目前,當(dāng)我使用 runserver ( http://127.0.0.1:8000/inventory/ ) 時,庫存視圖會顯示,但單擊任何行都不會執(zhí)行任何操作。這是我到目前為止所擁有的;庫存.html{% extends "base.html" %}{% block body %}<br><table class="table table-hover">    <thead>    <tr>        <th>Part Number</th>        <th>Description</th>        <th>Location</th>        <th>Supplier</th>        <th>S.O.H</th>    </tr>    </thead>    <tbody>    {% for part in parts %}    <!-- need to make these table rows link to their respective parts    class="table_row" href="{{ selected_part.partnumber }}/detail">{{ selected_part.partnumber }}-->    <tr data-href="{% url 'detail' part.pk %}">        <td>{{ part.pk }}</td>        <td>{{ part.partnumber }}</td>        <td>{{ part.description }}</td>        <td>{{ part.location }}</td>        <td>{{ part.supplier }}</td>        <td>{{ part.stockonhand }}</td>    </tr>    {% endfor %}    </tbody></table>{% endblock %}urls.pyfrom django.urls import pathfrom .views import *urlpatterns = [    path('inventory/', inventory_list, name='inventory'),  # URL path for inventory_list view    path('<str:pk>/', part_information, name='detail'),    path('', index, name='index'),]自定義.js$('tr[data-href]').on("click", function() {    document.location = $(this).data('href');});base.html<script src="/docs/4.4/dist/js/custom.js"></script>之前有</body>標(biāo)簽。我認為問題出在我的 javascript 文件中。我對此很陌生,非常感謝簡化的解釋
查看完整描述

1 回答

?
紅糖糍粑

TA貢獻1815條經(jīng)驗 獲得超6個贊

在您的 custom.js 文件中使用以下內(nèi)容。當(dāng)頁面被加載時,這個函數(shù) $(document).ready() 被執(zhí)行初始化 tr 做什么'On Click'


    $(document).ready(function(){

      $('table tr').click(function(){

        window.location = $(this).data('href');

        return false;

      });

    });


查看完整回答
反對 回復(fù) 2022-07-08
  • 1 回答
  • 0 關(guān)注
  • 128 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號