加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – jquery附加到输入值

发布时间:2020-12-13 16:26:57 所属栏目:PHP教程 来源:网络整理
导读:这是我的表格中的最后一个问题(希望如此) 我想要做的是将var大小附加到名为my-item-name的隐藏输入中 我试过添加这个 form.find('[name=my-item-name]').append(size.val()); 但它不起作用. 将大小val附加到输入的正确方法是什么? form method="post" actio
这是我的表格中的最后一个问题(希望如此)

我想要做的是将var大小附加到名为my-item-name的隐藏输入中

我试过添加这个

form.find('[name=my-item-name]').append(size.val());

但它不起作用.

将大小val附加到输入的正确方法是什么?

<form method="post" action="" class="jcart">
    <fieldset>
        <input type="hidden" name="jcartToken" value="13823c48f896c49403465fcce9f135ac" />

        <input type="hidden" name="my-item-id" value="12" />
        <input type="hidden" name="my-item-price" value="15.99" />
        <input type="hidden" name="my-item-url" value="http://yahoo.com" />
        <input type="hidden" name="my-item-name" value="Operation Braveheart hooded sweatshirt" />
        <ul>
            <li>
                <select name="my-select" id="foo12">
                    <option value='Small'>Small</option>
                    <option value='Medium'>Medium</option>
                    <option value='Large'>Large</option>
                    <option value='X-Large'>X-Large</option>
                </select>
            </li>
            <li>Price: $<span id="price12" class="price">15.99</span></li>
            <li>
                <label>Qty: <input type="text" name="my-item-qty" value="1" size="3" /></label>

            </li>
        </ul>

        <input type="submit" name="my-add-button" value="add to cart" class="button" />
    </fieldset>
</form>                
<script type="text/javascript">
    var item_prices_by_size12 = { "Small": { "Price": "15.99","ItemId": "9-1" },"Medium": { "Price": "16.99","ItemId": "9-2" },"Large": { "Price": "17.99","ItemId": "9-3" },"X-Large": { "Price": "18.99","ItemId": "9-4" }};
    $(function() {

        $('#foo12').change(function() {

            var form = $(this).parents('form');

            // Size is whatever the value the user has selected
            var size = $(this).val();

            // Determine the correct price and item ID based on the selected size
            var price12  = item_prices_by_size12[size].Price,itemId = item_prices_by_size12[size].ItemId;

            form.find('#price12').text(price12);

            form.find('[name=my-item-price]').val(price12);

            // Update the item ID
            form.find('[name=my-item-id]').val(itemId);

            form.find('[name=my-item-name]').append(size.val());

        });
    });
</script>
append:“将由参数指定的内容插入到匹配元素集合中每个元素的末尾.”

你想做的是追加我认为的价值?

var value = form.find('[name=my-item-name]').val();
form.find('[name=my-item-name]').val(value + size);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读