当一页上有超过24个表单时,操作表单数据

Manipulating form data when there are upwards of 24 forms on a page

本文关键字:表单 操作表 数据 操作 24个 一页      更新时间:2023-09-26

我不知道如何用词形容这个井的标题,如果问题不是你所期望的,我很抱歉。我在一页纸上有多达24张表格,格式如下:

<form id="prod-44" action="index.php" method="post">
    <div class="meta-info">
        <span id="prodWeight1" style="font-weight:bold;">£2.99</span>
        <span id="prodWeight2" style="font-weight:bold; display:none;">£3.99</span>
        <span id="prodWeight3" style="font-weight:bold; display:none;">£4.99</span>
        <span>
            <select class="44" name="weight">
                <option value="prodWeight1">180g</option>
                <option value="prodWeight2">240g</option>
                <option value="prodWeight2">300g</option>
            </select>
        </span>
    </div>
    <div class="add-to-basket">
        <input type="hidden" value="44" name="item-id">
        <input type="hidden" value="Product1" name="item-name">
        <input type="hidden" value="2.99" name="item-price">
        <input type="hidden" value="1" name="item-qty">
        <input class="add-product" type="submit" value="add" name="add-button">
    </div>
</form>

多亏了这个网站上的各位,我现在在Jquery/JS方面还不是一个完全的傻瓜,但我一辈子都不知道如何开始这个网站!:)由于这是页面上任何时候最多24个表单中的一个,所以我不能使用通用的$(this).change方法来获取正在更改的单个<select>值。我正试图根据重量显示正确的价格。作为selectparent的同级元素的三个<span>标记是我试图更改的三个标记。

我甚至无法发布我的工作Jquery,因为我甚至无法让它识别哪个select元素发生了变化:(有人能帮我指出正确的方向吗?

$("select").change(function(){
 var p = $(this).parents("div");
 var c = p.find("#"+$(this).val()).html()
 // in c is now actual SPAN html text reached by id stored in select value
})