springboot怎么把数据传给前端:springboot 如何引入前端 bootstrap?
这种问题网上一搜一大堆,你可以具体找一篇文章试试,遇到问题可以针对相关问题去提问。springboot通过jar包方式引入bootstrap_个人文章 - SegmentFault 思否 这不是查查就
顺晟科技
2022-10-18 13:50:27
29
我有一个名为BuyAnimal(ID)的JS函数,如果我将index.HTML设置为include
,它就会按预期工作。<div onclick="buyAnimal(0)"></div>
它可以正常工作,但如果我使用
let html = `<div onclick="buyAnimal(0)"></div>`
$('#element').html(html);
onclick功能没有通过,这是正常的,还是我必须用我的JS专门附加一个onclick函数到该元素?
顺晟科技:
<块引用>我是否必须专门将onclick函数附加到该元素?用我的JS?
你不需要这么做。您可以查看下面的演示。
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="element"></div>
<代码><;script SRC=“ https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js ”>;<;/script>;<;DIV ID=“元素”>;<;/DIV>;
您应该通过以下方式
将事件句柄附加到动态DIV$(document).on("click", '.buy', function() {
buyAnimal(0);
});
let html = `<div class='buy'>BUY</div>`
$('#element').html(html);
$(document).on("click", '.buy', function() {
buyAnimal(0);
});
function buyAnimal(n){
console.log('buy...' + n);
}
<代码><;script SRC=“ https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js ”>;<;/script>;<;DIV ID=“元素”>;<;/DIV>;
05
2022-12
02
2022-12
02
2022-12
29
2022-11
29
2022-11
24
2022-11