首页 > 解决方案 > 如何在 Laravel 中包装 JavaScript 跨度 ID

问题描述

我想发送跨度ID。我已经在刀片文件中尝试了这些代码,但我无法获得价值。请教我怎么写代码好吗?

<input type="hidden" name="quantity" value="<span id="quantity"></span>">

<input type="hidden" name="quantity" value="<span id=&quot;quantity&quot;></span>">

更新

我写了这个但是“数量”值是这个“”

const priceAch = comma(parseInt(String(typeValue * productValue * quantity)));
document.getElementById('edit-quantity').value = priceAch;

在此处输入图像描述

标签: javascriptlaravel

解决方案


如果我误解了你的问题,请原谅我,但如果你试图让你的 span 标签之间的 HTML 值成为你隐藏输入的值,你可以按照以下方式做一些事情:

<span id="quantity">23</span>
<input id="edit-quantity" type="hidden">

<script>
    document.getElementById('edit-quantity').value = document.getElementById('quantity').innerText;
</script>

这会将输入元素的 value 属性设置为 span 标签之间的文本。在上述场景中,输入值将返回“23”。


推荐阅读