简体   繁体   English

使用onclick事件更改对象html标签的数据

[英]Change data of object html tag with onclick event

I'm using Thymeleaf and Sprin Boot I have an object like this inside my page: 我正在使用Thymeleaf和Sprin Boot,我的页面内有一个这样的对象:

Then I want to change the content of the object after an onclick event: I chose a date, after I confirm it, I send a request to the server and I have to show the answer (a pdf) inside the object 然后,我想在onc​​lick事件之后更改对象的内容:我选择了一个日期,在确认日期之后,我向服务器发送了一个请求,我必须在对象内部显示答案(pdf)

How can I do it? 我该怎么做?

This is the entire page: 这是整个页面:

    <div class="row">
        <div class="col">
            <h5 style="color:red;">Seleziona data</h5>
            <div class="input-group input-group-prepend col-4">
                <span class="input-group-text far fa-calendar-alt"></span>
                <input type="text" class="form-control date" data-provide="datepicker" id="dataProgrammazione" ></input>
            </div>
            <button type="button" class="btn btn-primary" th:text="#{conferma}" onclick="cambiaData();"></button>
        </div>
    </div>
    <div class="row">
        <object class="col" th:data="@{/programmazione/pdf?dataProva=16/04/2018}" type="application/pdf" height="800" width="800" id="pdf"></object>
    </div>

    <script type="text/javascript">

        function cambiaData(){
            $.ajax({
                type: 'GET',  
                url: MY_URL+$("dataProgrammazione").val(),
                success: function(results) {
                    alert(results);
                    $('#pdf').data(results);
                }
            });
        }

        $(function(){
            $(".date").datepicker({
                todayBtn: "linked",
                language: "it",
                todayHighlight: true
            });
        });
    </script>

You can do something like: 您可以执行以下操作:

<script type="text/javascript" th:inline="javascript">
    /*<![CDATA[*/
        function cambiaData(){
            $('#pdf').attr("data", [[ @{'NEW_URL_WITH_NEW_DATA}]]+$("#data").val());
        }

        $(function(){
            $(".date").datepicker({
                todayBtn: "linked",
                language: "it",
                todayHighlight: true
            });

        });
    /*]]>*/
    </script>

and

<div class="row">
        <h5 style="color:red;">Seleziona data</h5>
        <div class="input-group input-group-prepend col-2">
            <span class="input-group-text far fa-calendar-alt"></span>
            <input type="text" class="form-control date" data-provide="datepicker" id="data" th:value="${#dates.format(#dates.createNow(), 'dd/MM/yyyy')}"></input>
        </div>
        <button type="button" class="btn btn-primary" th:text="#{conferma}" onclick="cambiaData();"></button>
</div>
<div class="row">
    <object class="col" th:data="@{URL}" type="application/pdf" height="800" width="800" id="pdf"></object>
</div>

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

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