Visualizzazione dei risultati da 1 a 2 su 2

Discussione: bootstrap table button

  1. #1

    bootstrap table button

    ho una tabella creata con bootstrap-table :

    codice:
    <table id="table" class="table table-bordered table-striped table-hover" data-toolbar="#toolbar">
        <thead>
            <tr class="mxn-header-table">
                <th class="text-center" style="" data-field="componenti_nucleo_familiare">
                    <div class="th-inner ">Componente</div>
                    <div class="fht-cell"></div>
                </th>
                <th class="text-center" style="" data-field="nome_cognome">
                    <div class="th-inner ">Nome e Cognome</div>
                    <div class="fht-cell"></div>
                </th>
                <th class="text-center" style="" data-field="lavoro_anno_precedente">
                    <div class="th-inner ">Lavorato nell'anno precedente</div>
                    <div class="fht-cell"></div>
                </th>
                <th class="text-center" style="" data-field="lavoro_anno_attuale">
                    <div class="th-inner ">Lavorato nell'anno attuale</div>
                    <div class="fht-cell"></div>
                </th>
                <th class="text-center" style="" data-field="tipo_contratto">
                    <div class="th-inner ">Tipo contratto</div>
                    <div class="fht-cell"></div>
                </th>
                <th class="text-center" style="" data-field="reddito_autonomo">
                    <div class="th-inner ">Reddito autonomo</div>
                    <div class="fht-cell"></div>
                </th>
                <th class="text-center" style="" data-field="id">
                    <div class="th-inner "><i class="icofont-trash"></i></div>
                    <div class="fht-cell"></div>
                </th>
            </tr>
        </thead>
        <tbody id="body_table">
            <tr data-index="0">
                <td class="text-center">Dichiarante</td>
                <td class="text-center">pippo baudo</td>
                <td class="text-center">Si</td>
                <td class="text-center">Si</td>
                <td class="text-center">Tempo determinato</td>
                <td class="text-center">0</td>
                <td class="text-center"><button type="button" class="eliminacomponente btn btn-danger" value="17"><i
                            class="icofont-trash"></i></button></td>
            </tr>
            <tr data-index="1">
                <td class="text-center">Coniuge</td>
                <td class="text-center">pippo poppo</td>
                <td class="text-center">Si</td>
                <td class="text-center">Si</td>
                <td class="text-center">Tempo determinato</td>
                <td class="text-center">0</td>
                <td class="text-center"><button type="button" class="eliminacomponente btn btn-danger" value="18"><i
                            class="icofont-trash"></i></button></td>
            </tr>
            <tr data-index="2">
                <td class="text-center">Altro componente del nucleo familiare</td>
                <td class="text-center">ee</td>
                <td class="text-center">Si</td>
                <td class="text-center">Si</td>
                <td class="text-center">Tempo determinato</td>
                <td class="text-center">0</td>
                <td class="text-center"><button type="button" class="eliminacomponente btn btn-danger" value="19"><i
                            class="icofont-trash"></i></button></td>
            </tr>
            <tr data-index="3">
                <td class="text-center">Altro componente del nucleo familiare</td>
                <td class="text-center">ee</td>
                <td class="text-center">Si</td>
                <td class="text-center">Si</td>
                <td class="text-center">Tempo determinato</td>
                <td class="text-center">0</td>
                <td class="text-center"><button type="button" class="eliminacomponente btn btn-danger" value="20"><i
                            class="icofont-trash"></i></button></td>
            </tr>
            <tr data-index="4">
                <td class="text-center">Dichiarante</td>
                <td class="text-center">rosanna pieri</td>
                <td class="text-center">Si</td>
                <td class="text-center">Si</td>
                <td class="text-center">Tempo determinato</td>
                <td class="text-center">0</td>
                <td class="text-center"><button type="button" class="eliminacomponente btn btn-danger" value="21"><i
                            class="icofont-trash"></i></button></td>
            </tr>
            <tr data-index="5">
                <td class="text-center">Altro componente del nucleo familiare</td>
                <td class="text-center">hhhh</td>
                <td class="text-center">Si</td>
                <td class="text-center">Si</td>
                <td class="text-center">Tempo determinato</td>
                <td class="text-center">0</td>
                <td class="text-center"><button type="button" class="eliminacomponente btn btn-danger" value="22"><i
                            class="icofont-trash"></i></button></td>
            </tr>
    
    
        </tbody>
    </table>
    negli script js ho :

    codice:
    $( ".eliminacomponente" ).click(function() {
    
    
    
    
        var id_componente = $(this).val();
    
    
        console.log('!'+id_componente);
    
    
    });
    Perchè quando premo su un pulsante in console non appare niente ?

    edit messo il codice del js nel document ready funziona...
    Ultima modifica di pippuccio76; 17-02-2021 a 01:22

  2. #2
    Utente di HTML.it L'avatar di ninja72
    Registrato dal
    May 2020
    residenza
    -
    Messaggi
    319
    In console ricevo il valore relativo al bottone cliccato , forse hai dimenticato di inserire qualche dipendenza nel file html.


    head html
    codice:
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
        <link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.18.2/dist/bootstrap-table.min.css">
    prima del del tag </body>
    codice:
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
        <script src="https://unpkg.com/bootstrap-table@1.18.2/dist/bootstrap-table.min.js"></script><script src="main.js"></script>
       <script>
            $(".eliminacomponente").click(function () {
                const id_componente = $(this).val();
                console.log('!' + id_componente);
            });
        </script>

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.