javascript - 如何在另一个 html 文件中的表单中使用一个 html 文件中表中的值

标签 javascript jquery html

这是为了构建一个保存产品数据的表:我想要表的数量部分并将其用作另一种形式的变量,并在另一个函数中使用它。

{{#viewTableData}}
<tr class="view-product-row">
<td class="product-name" data-product-id="{{ id }}">{{ name }}</td>
<td class="product-maker-number" data-product-id="{{ id }}">{{ makerNumber }}</td>
<td class="product-jan-code" data-product-id="{{ id }}">{{ janCode }}</td>
<td class="product-current-quantity">{{ quantity }}</td>
<td style="text-align: center">
    <button type="button" class="btn btn-info edit-current-quantity-button" data-toggle="modal" data-target="#edit-current-quantity-modal"><span class="glyphicon glyphicon-pencil"></span></button>
        &nbsp;&nbsp;&nbsp;
    <button type="button" class="btn btn-success new-movement-button" data-toggle="modal" data-target="#movement-modal"><span class="glyphicon glyphicon-plus"></span></button>
</td>
</tr>
 {{/viewTableData}}

 {{^viewTableData}}
 <tr>
<td colspan="5">
    {{#i18n}}inventory.view.no-data{{/i18n}}
</td>
</tr>
{{/viewTableData}}
<script>
$(document).ready(function() {
    $('.edit-current-quantity-button').on('click', function() {populateEditCurrentQuantityModal(this)});
    $('.new-movement-button').on('click', function() {populateNewMovementModalFromView(this)});
});
</script>

我想知道如何从该函数获取数量到另一个 html 文件中的函数

function getCurrentQuantity()
{
    //find the item and the store and get the quantity
    //get data from the database
    //Use store id and jan code for the query 
    //That way both get updated when either is changed
    //product-jan-code and store-from

    var q = $(".store-from-current-quantity").val(); // this does not work this is the input where the quantity from the other class should go


    //update the UI if it is not done auto
    fromStoreCurrentQuantity.value = q;
    return q;
}

最佳答案

您可以将该值保存在 Cookie 或 localStorage 中,以便从其他 HTML 页面访问它。

检查此链接:Sharing a variable between multiple html pages

关于javascript - 如何在另一个 html 文件中的表单中使用一个 html 文件中表中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40013582/

相关文章:

javascript - 限制格式化用户输入的宽度 - Javascript、CSS 或 jQuery

javascript - HTML - 使表格最小高度与当前屏幕高度匹配

html - 应用于特定 DIV 的 CSS 会遗漏一些细节

javascript - jquery getJSON() 函数(获取整个 json 对象)

JavaScript 无法验证 HTML 中的表单

javascript - 我想在 laravel 中验证像 111-244-123 这样的数据

javascript - 使用 jquery 更新图像源无法正常工作

jquery - 如何手动加载jqgrid中的数据?

javascript - 如何组织复杂的 jquery 应用程序?

java - 如何在非webapp maven项目中添加和打开html文件