简体   繁体   English

单击按钮表单后隐藏许多div

[英]Hide many div after click on button form

In this part of code I have several forms generated automatically by thymeleaf, each of which allows you to vote for a web location, now I would like that once you click on a question of a specific web location, the others automatically hide from the view. 在这部分代码中,我有thymeleaf自动生成的几种表单,每种表单都可以让您投票给某个Web位置,现在我希望一旦您单击特定Web位置的问题,其他表单就会自动从视图中隐藏。

For example, if I have 3 web locations and vote for a web location question with id = 2, web locations with id = 1.3 hide automatically. 例如,如果我有3个网站并投票给ID = 2的网站问题,ID = 1.3的网站会自动隐藏。

 <div th:each="childLocation : ${childLocations}"> <form th:action="@{/sendVote}" enctype="multipart/form-data" method="post" data-successHandler="afterOpinionSent" class="s_ajaxForm" th:object="${childLocation}"> <input type="hidden" name="webLocationId" th:value="${childLocation.id}" th:if="${childLocation!=null}"/> <div th:each="webQuestion : ${@webQuestionRepository.findByWebLocation(childLocation.id)}" class="row sinWebQuestion" style="margin-bottom: 20px;"> <div class="col-sm-12"> <div th:text="${webQuestion.question}" class="sinButtonVoteLabel" style="text-align: center;">How Do?</div> </div> <div class="col-sm-12" style="text-align: center;"> <label th:each="vote : ${ {3, 2, 1, 0} }" class="radio-inline sinButtonVote" style="margin-top: 10px;"> <input type="radio" th:name="|questionVote[${webQuestion.id}]|" th:value="${vote}" /> <img yada:src="@{|/res/img/question/${webQuestion.iconName+vote}.png|}" th:alt-title="|Vote ${vote}|"> </label> </div> </div> <button th:id="|sendVoteButton${childLocation.id}|" type="submit" class="s_ajaxForm btn btn-default btn-block hidden">Send Opionion</button> </form> </div> 

I try to use inline javascript: 我尝试使用内联javascript:

 <script type="text/javascript" th:inline="javascript"> /*<![CDATA[*/ $(".sinButtonVote > img").click(function(e){ $(this).parents("div.sinWebQuestion").addClass("voteChosen"); $("#sendVoteButton[(${childLocation.id})]").removeClass("hidden"); $("#sendOpinion[(${childLocation.id})]").removeClass("hidden"); /*[# th:each="n : ${childLocations}"]*/ if([(${n.id})]!=[(${childLocation.id})]) { $("#sinVoto[(${childLocation.id})]").hide() /*[/]*/ }); function afterOpinionSent() { $("div.sinVotoInner").addClass("hidden"); } /*]]>*/ </script> 

Once you click on the question hide all div. 单击问题后,隐藏所有div。

How can I fix the problem? 我该如何解决该问题?

try this code: 试试这个代码:

<script type="text/javascript" th:inline="javascript">
    /*<![CDATA[*/
    $(".sinButtonVote > img").click(function(e){
        $(this).parents("div.sinWebQuestion").addClass("voteChosen");
        $("#sendVoteButton[(${childLocation.id})]").removeClass("hidden");
        $("#sendOpinion[(${childLocation.id})]").removeClass("hidden");

        /*[# th:each="n : ${childLocations}"]*/
        if([(${n.id})]!=[(${childLocation.id})]) {
            $("#sinVoto[(${childLocation.id})]").hide()
         /*[/]*/


    /** this is the new code **/
        }

        afterOpinionSent();
    });

    /** end of new code **/

    function afterOpinionSent() {
            $("div.sinVotoInner").addClass("hidden");
        }
    /*]]>*/
</script>

I've added an extra } to close the img click callback function, and I also call your afterOpinionSent function because this was not being called. 我添加了一个额外的}以关闭img click回调函数,并且我也调用了afterOpinionSent函数,因为未调用此函数。

Try this: 尝试这个:

<script type="text/javascript" th:inline="javascript">
            /*<![CDATA[*/               
function hiddenFunction(xId){
            var userInput = document.getElementById("webLocationId"+xId).value;
            document.getElementById("userInputId").innerHTML = userInput;
            /*[# th:each="n : ${childLocations}"]*/
                if([(${n.id})]!=userInput) {
                    $("#sinVoto[(${n.id})]").addClass("hidden");
                }
            /*]]>*/
        </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM