Target and HTML code
Target: Click on JQ Delete, get the ID of the whole line TR, (the backend part is slightly, pass ID processing can), the page deletes the TR line
<tr myid="{{ cls.id }}"> .... <td><a onclick="rmStu(this);" class="abc" href="#">jq删除</a></td>
"Mode 1" is triggered by the onclick, click Position by this pass dynamic variable concatenation by string
<script> function rmStu(th) { var myid=$(th).parent().parent().attr(‘myid‘); alert(myid);{# $(th).parent().parent().remove();#}{# $("[myid=‘11‘]").remove();#}{# $("[myid=myid]").remove();无法定位#} $("[myid="+myid+"]").remove(); }</script>
the "mode 2" event binding. Click Trigger when the condition is any class= "abc". When triggered by $ (this) to get the click location
<script> $(function () { bindEvent(); }); function bindEvent() { $(‘.abc‘).click(function () { var myid=$(this).parent().parent().attr(‘myid‘); alert(myid); }) }</script>
Appendix Bootstrap modal show
<script src="/static/jquery-3.3.1.js"></script><script src="/static/plugin/bootstrap-3.3.7/js/bootstrap.js"></script><script> $(function () { abc(); }); function abc() { $(‘#showmyModal‘).click(function () { $(‘#myModal‘).modal(‘show‘); }) }</script>
"1" click-to-pass position "2" click Trigger function, multiple places can be triggered, then get the position "3" howto dynamic ID, binding mode, click-to-pass?
Front End: jquery event bindings and selectors using dynamic variables