简体   繁体   English

如何在 HTML 中使用变量

[英]How to use a variable in HTML

I am trying to use a variable in my HTML file called "Description", that I defined like this:我试图在我的 HTML 文件中使用一个名为“描述”的变量,我定义如下:

       <h1 th:text="'Product ' + ${item.itemCode}"></h1>
            <div class="inset">
                <p>
                    <label>Item Code</label>
                    <b th:text= "${item.itemCode}"></b>
                <p>
                <p>
                    <label>Item Description</label>
                    <b th:text= "${item.Description}" contenteditable="true" name="Description" id="Description"></b>
                <p>
                <p>
                    <label>Item Price</label>
                    <b th:text= "${item.Price}" contenteditable="true" name="price" id="price"></b>
                <p>
                <p>
                    <label>Item Creation Date</label>
                    <b th:text= "${item.creationDate}" contenteditable="true" name="date" id="date"></b>
                <p>
                <p>
                    <label>Item Creator</label>
                    <b th:text= "${item.creatorUser}" contenteditable="true" name="creator" id="creator"></b>
                <p>
                <p>
                    <label>Item State</label>
                    <b th:text= "${item.itemEnum.getEstado()}"></b>
                <p>

                <p>
                    <a th:href="@{/api/item/saveChanges(itemCode = ${item.itemCode}, description = getVariable())}"> <input name="submit" type="submit" value="Save Changes" /></a>
                </p>
                <p th:if="${item.itemEnum.getEstado() == 'Active'}">
                    <a th:href="@{/api/item/changeInactive/{itemCode}(itemCode = ${item.itemCode})}"> <input name="submit" type="submit" value="Deactivate" width="100%"/></a>
                </p>
                <p th:if="${item.itemEnum.getEstado() == 'No Active'}">
                    <a th:href="@{/api/item/changeActive/{itemCode}(itemCode = ${item.itemCode})}"> <input name="submit" type="submit" value="Activate" width="100%" /></a>
                </p>

            </div>
<script>
    function getVariable(){
        return document.getElementById("Description");
    }
</script>

Basically, I get that variable from my controller.基本上,我从我的控制器中得到那个变量。 However, it is editable.但是,它是可编辑的。 What I want is to be able to get the current value of "Description" so I can send it back to the controller to update it, something like this:我想要的是能够获取“描述”的当前值,以便我可以将其发送回控制器以更新它,如下所示:

<a th:href="@{/api/item/saveChanges(description = ${Description})

You can use it something like this:你可以像这样使用它:

<textarea rows="7" cols="10" th:text= "${item.Description}" name="Description" >

Receive it in the controller, if the user updates it, you will get an updated value.在控制器中接收它,如果用户更新它,您将获得更新的值。

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

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