尝试为 AEM 中的多个按钮组件实现 onclick 标记加载需要有关最佳实践的建议。以下是我实施的方法。有人可以帮我解决这个问题。提前致谢!
<sly data-sly-test="${properties.tag}">
<script>
$(".input1-tag").click(function(e){
e.preventDefault();
var href = $(this).attr("href");
$("body").append("<img src=\" ${properties.tag @ context ='scriptString'} \" width="1" height="1" alt="" />");
window.location = href;
});
</script>
</sly>
<sly data-sly-test="${properties.optionaltag}">
<script>
$(".input2-tag").click(function(e){
e.preventDefault();
var href = $(this).attr("href");
$("body").append("<img src=\" ${properties.optionaltag @ context ='scriptString'} \" width="1" height="1" alt="" />");
window.location = href;
});
</script>
</sly>
<sly data-sly-test="${properties.thirdtag}">
<script>
$(".input3-tag").click(function(e){
e.preventDefault();
var href = $(this).attr("href");
$("body").append("<img src=\" ${properties.thirdtag @ context ='scriptString'} \" width="1" height="1" alt="" />");
window.location = href;
});
</script>
</sly>