Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
458 views
in Technique[技术] by (71.8m points)

css - Make Icon Clickable in HTML

I am essentially trying to replace the following EDIT and DELETE buttons with icons, but am running into issues trying to do this within HTML. The OnClick function doesn't seem to do anytihng when I click the buttons. Any ideas on how to adjust this code?

html

<div style="height:400px; overflow:auto; margin:0px 20px 20px 20px">
    <table id="userTable" class="table table-striped" style="font-family: graphik">
        <tr>
            <th>Employee</th>
            <th>Description</th>
            <th colspan="3">Stakeholder Group</th>
        </tr>
        {% for user in users %}
        <tr id="user-{{user.id}}">
            <td class="useremployee userData" name="employee">{{user.employee}}</td>
            <td class="userdescription userData" name="description">{{user.description}}</td>
            <td class="userstakeholder_group userData" name="stakeholder_group">{{user.stakeholder_group}}</td>
            <td align="center">
                <button class="btn btn-success form-control" onClick="editUser({{user.id}})" data-toggle="modal" data-target="#myModal" )">EDIT</button>
            </td>
            <td align="center">
                <img class="d-block w-100" src="{% static 'polls/images/edit.png' %}" style="cursor:pointer; width: 30px; height: 30px" alt="opmodel">
            </td>
            <td align="center">
                <img class="d-block w-100" onClick="editUser({{user.id}})" src="{% static 'polls/images/delete.png' %}" style="cursor: pointer; width: 30px; height: 30px" alt="opmodel">
            </td>
            <td align="center">
                <button class="btn btn-danger form-control" onClick="deleteUser({{user.id}})">DELETE</button>
            </td>
        </tr>
        {% endfor %}
    </table>
</div>

enter image description here

question from:https://stackoverflow.com/questions/65516930/make-icon-clickable-in-html

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think putting the image inside a link tag should do the trick

<td align="center">
    <a href="editUser({{user.id}})">
        <img class="d-block w-100" src="{% static 'polls/images/edit.png' %}" style="cursor:pointer; width: 30px; height: 30px" alt="opmodel">
    </a>
</td>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...