Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

thymeleaf中使用layui动态生成的按钮,无法监听按钮的click事件

<div th:each="answer,answerStat:${question.getAnswers()}" class="layui-col-md8 layui-col-md-offset2" style="background-color: #fff;margin-top: 20px;">
        <div class="" style="font-size: 1.2em;background-color: #fff;">
            <div class="layui-btn-group">
                <button type="button" class="layui-btn layui-btn-primary">
                    <i class="layui-icon">&#xe6c6;</i>
                </button>
                <button type="button" class="layui-btn layui-btn-primary">
                    <i class="layui-icon">&#xe6c5;</i>
                </button>
                <button type="button" th:id="talk+(${answer.id})" th:onclick="show('talk',[[${answer.id}]]);" class="layui-btn layui-btn-primary">
                    <i class="layui-icon">&#xe611;</i>
                </button>
            </div>
            <div th:id="Input+(${answer.id})" class="layui-hide layui-form" style="margin-top: 5px;">
                <div class="layui-form-item">
                    <input type="text"  class="layui-input" placeholder="输入评论" />
                </div>
                <div class="layui-btn-group">
                    <button type="button" th:id="answer+(${answer.id})" class="layui-btn layui-btn-primary">
                        <i class="layui-icon">提交评论</i>
                    </button>
                </div>

            </div>
        </div>
window.show= function (str,id) {
            id = str+id;
            console.log(id);
            $("div[id^=id]").removeClass("layui-hide");
        }

想着可能是模板引擎加载可能是异步,但是使用th:click还是没用


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...