jquery has no effect on the click event of the js code generated later

The click event written directly in the page is valid:

<a class="deleteCls" beanId="${bean.id }" href="javascript:void(0)">删除</a>
$("a.deleteCls").click(function() {
      alert("del");
    });

 

 

But the code generated in js:

str += "<td><a class='deleteCls' beanId='" + item.id + "' href='javascript:void(0)'>删除</a></td>";

The click is invalid. I checked the information and said that it was the code generated later. jQuery did not bind the click event. Specifically, I did not do any in-depth understanding.

Here is the workaround:

Will

 

$("a.deleteCls").click(function() {
      alert("del");
    });

 

Modify it to (tableList is the id of the table table, and the generated code is in the table tag):

$("#tableList").on("click","a.deleteCls",function(){
    alert("del");
    });

 

 

Solved, now the click event of the generated code can also respond!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326390662&siteId=291194637