1
在同一页面我有两种形式,我希望能够修改表单1,修改出现在表单2副本(两种方式)中。2 Jquery的形式
它对于“数量”的输入字段工作正常,但我有问题与2选择菜单。
正如你所看到的,我使用了OnPress
作为数量,因为onChange
没有工作!所有的
$("#Quantity").change(function() {
$("#Quantity_2").val($(this).val());
});
$("#Quantity_2").change(function() {
$("#Quantity").val($(this).val());
});
$("#SingleOptionSelector_0").change(function() {
$("#SingleOptionSelector_0_2").val($(this).val());
});
$("#SingleOptionSelector_0_2").change(function() {
$("#SingleOptionSelector_0").val($(this).val());
});
$("#SingleOptionSelector_1").change(function() {
$("#SingleOptionSelector_1_2").val($(this).val());
});
$("#SingleOptionSelector_1_2").change(function() {
$("#SingleOptionSelector_1").val($(this).val());
});
function updateQuantity_2(val) {
$("#Quantity").val(val);
$("#Quantity").trigger('change');
}
function updateQuantity(val) {
$("#Quantity_2").val(val);
$("#Quantity_2").trigger('change');
}
function updateSingleOptionSelector_0_2(val) {
$("#SingleOptionSelector_0 option:selected").val(val);
$("#SingleOptionSelector_0 option:selected").trigger('change');
}
function updateSingleOptionSelector_0(val) {
$("#SingleOptionSelector_0_2 option:selected").val(val);
$("#SingleOptionSelector_0_2 option:selected").trigger('change');
}
function updateSingleOptionSelector_1_2(val) {
$("#SingleOptionSelector_1 option:selected").val(val);
$("#SingleOptionSelector_1 option:selected").trigger('change');
}
function updateSingleOptionSelector_1(val) {
$("#SingleOptionSelector_1_2 option:selected").val(val);
$("#SingleOptionSelector_1_2 option:selected").trigger('change');
}
<form action="/cart/add" method="post" enctype="multipart/form-data" data-section="{{ section.id }}">
<select onChange="updateSingleOptionSelector_0_2()" id="SingleOptionSelector_0" data-index="option{{ forloop.index }}">
{% for value in option.values %}
<option value="{{ value | escape }}"{% if option.selected_value == value %} selected="selected"{% endif %}>{{ value }}</option>
{% endfor %}
</select>
<select onChange="updateSingleOptionSelector_1_2()" id="SingleOptionSelector_1" data-index="option{{ forloop.index }}">
{% for value in option.values %}
<option value="{{ value | escape }}"{% if option.selected_value == value %} selected="selected"{% endif %}>{{ value }}</option>
{% endfor %}
</select>
<select name="id" id="ProductSelect-{{ section.id }}" data-section="{{ section.id }}" class="product-form__variants no-js">
{% for variant in product.variants %}
{% if variant.available %}
<option {% if variant == product.selected_or_first_available_variant %} selected="selected" {% endif %} value="{{ variant.id }}">
{{ variant.title }}
</option>
{% else %}
<option disabled="disabled">{{ variant.title }} - {{ 'products.product.sold_out' | t }}</option>
{% endif %}
{% endfor %}
</select>
<label for="Quantity">{{ 'products.product.quantity' | t }}</label>
<input type="number" id="Quantity_2" onPress="updateQuantity()" name="quantity" value="1" min="1" class="product-form__input" pattern="[0-9]*">
<button type="submit" name="add" id="AddToCart-{{ section.id }}">ADD TO CART</button>
</form>
<form action="/cart/add" method="post" enctype="multipart/form-data" data-section="{{ section.id }}">
<select onChange="updateSingleOptionSelector_0()" id="SingleOptionSelector_0_2" data-index="option{{ forloop.index }}">
{% for value in option.values %}
<option value="{{ value | escape }}"{% if option.selected_value == value %} selected="selected"{% endif %}>{{ value }}</option>
{% endfor %}
</select>
<select onChange="updateSingleOptionSelector_1()" id="SingleOptionSelector_1_2" data-index="option{{ forloop.index }}">
{% for value in option.values %}
<option value="{{ value | escape }}"{% if option.selected_value == value %} selected="selected"{% endif %}>{{ value }}</option>
{% endfor %}
</select>
<select name="id" id="ProductSelect-{{ section.id }}" data-section="{{ section.id }}" class="product-form__variants no-js">
{% for variant in product.variants %}
{% if variant.available %}
<option {% if variant == product.selected_or_first_available_variant %} selected="selected" {% endif %} value="{{ variant.id }}">
{{ variant.title }}
</option>
{% else %}
<option disabled="disabled">{{ variant.title }} - {{ 'products.product.sold_out' | t }}</option>
{% endif %}
{% endfor %}
</select>
<label for="Quantity">{{ 'products.product.quantity' | t }}</label>
<input type="number" id="Quantity_2" onPress="updateQuantity()" name="quantity" value="1" min="1" class="product-form__input" pattern="[0-9]*">
<button type="submit" name="add" id="AddToCart-{{ section.id }}">ADD TO CART</button>
</form>
请格式化你的HTML代码(使用计划),这是很难在当前状态下读取代码。 –
从选择器中删除'option:selected'。 –