简体   繁体   English

单击时刷新div contenct

[英]Refresh div contenct on click

I've this problem: 我有这个问题:

I want to reload this div, made with Java Spring, when the user clicks on a button: 当用户点击按钮时,我想重新加载使用Java Spring创建的div:

<div id="trigger-who" class="page" th:fragment="triggerWho">
        <h3><strong class="accent">Which</strong> service will activate the rule?</h3>

        <ul id="trigger" class="list list-horizontal">
            <li th:each="channel: ${channels}"
                th:with="service=${channel.getService()}"
                th:if="${channel.getService().getTriggers().size() != 0}">
                <figure
                    class="service-box"
                    data-trigger="trigger"
                    th:attr="data-service-name=${service.getName()},data-service-connected=${channel.isConnected()}">
                    <img th:id="${service.getName()}" th:src="@{/img/} + ${service.getName()} + '.png'" />
                    <figcaption th:text="${service.getName()}"></figcaption>
                </figure>
            </li>
        </ul>
        <br clear="all" />
</div>

In particular, I want to update the attribute "data-service-connected". 特别是,我想更新属性“data-service-connected”。

I've tried the load() method: 我尝试过load()方法:

$("#trigger-who").load(location.href + "#trigger-who"),

but it doesn't work fine. 但它不能正常工作。 It puts the whole page in the div. 它将整个页面放在div中。

Anyone have some suggestion? 有人有什么建议吗?

Thanks in advance for any answer. 提前感谢您的回答。

You want to load a "fragment" of the page. 您想加载页面的“片段”。

Using this: 使用这个:
$("#trigger-who").load(location.href + "#trigger-who")

The whole page is loaded : http://www.domain.com/#trigger-who 整个页面已加载: http//www.domain.com/#trigger-who
( #trigger-who is considered as a hash in the address) . #trigger-who被视为地址中的哈希)

Using a space between the address and "hash part" indicates that it is a jQuery selector. 在地址和“哈希部分”之间使用空格表示它是一个jQuery选择器。
$("#trigger-who").load(location.href + " #trigger-who")

The .load() method, unlike $.get(), allows us to specify a portion of the remote document to be inserted. 与$ .get()不同,.load()方法允许我们指定要插入的远程文档的一部分。 This is achieved with a special syntax for the url parameter. 这是通过url参数的特殊语法实现的。 If one or more space characters are included in the string, the portion of the string following the first space is assumed to be a jQuery selector that determines the content to be loaded. 如果字符串中包含一个或多个空格字符,则假定第一个空格后面的字符串部分是确定要加载的内容的jQuery选择器。

See documentation . 文档

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

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