简体   繁体   中英

How to make jsp table row clickable to call javascript function

I have a jsp table as follows.

<ul class="list-group list-group-flush" id="patternList">
    <c:forEach var="pattern" items="${patterns}">
        <li class="list-group-item liitem">
            <strong>${pattern.id}:</strong>
            <span class="pull-right" onclick="test('${pattern.name'})">${pattern.name}</span>
        </li>
    </c:forEach>
</ul>

I want to call following javascript function when click on table row. How can I do that.

function test (name) {
    alert(name);
}

I hope you have the jquery added to the jsp , bind the onclick event to the class pull-right ,

$(document).on('click', '.pull-right', function(){
  alert("I am clicked and value inside me is " + this.textContent );
});

this.textContent retrieves the value inside the span

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM