Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery更改事件修改两个不同的id和值_Javascript_Jquery - Fatal编程技术网

Javascript jquery更改事件修改两个不同的id和值

Javascript jquery更改事件修改两个不同的id和值,javascript,jquery,Javascript,Jquery,我有这样的密码: <script type="text/javascript"> $('#m_pair').on('change', function() { if ($(this).val() == 'pair'){ $ilosc_pair = $('#quantity_wanted').val(); $ilosc_pair = $ilosc_pair * 2; $("#quantity_want

我有这样的密码:

<script type="text/javascript">
$('#m_pair').on('change', function() {              
    if ($(this).val() == 'pair'){ 
        $ilosc_pair = $('#quantity_wanted').val();
        $ilosc_pair = $ilosc_pair * 2;
        $("#quantity_wanted").val($ilosc_pair).change();
        $("#group_5").val("35").change();   
    } else if ($(this).val() == 'single'){ 
        $("#group_5").val("34").change(); 
    }
});
</script> 

代码应该正常工作,但他们都不想工作

事件在一个html下拉列表更改时开始,并且应该更改一个文本字段和另一个下拉列表

编辑:

编辑:


@约翰:是的,有个问题。我现在还没有找到它,但在某处有另一个evend处理程序将值更改回原来的值。我只是不明白为什么我要用一个。更改它会被覆盖,而当我使用2x时。不更改。无论如何,谢谢你们的帮助,并跟踪我找到正确的方向:

为什么要使用.change?其中一个元素是下拉列表,没有它就不能更改。changeOne不应该在单个HTML中有重复的ID。。无效标记…可以使用DOM通配符命中多个元素*[id^=组^]。或者你想怎么用它,你应该摆弄它。我不太明白背后的逻辑。
`$("#quantity_wanted").val($ilosc_pair).change();` 
`$("#group_5").val("35").change();`   
<form id="form3" name="form3" method="post" action="">
   <label for="Heading">Heading</label>
   <select name="m_heading" id="m_heading">
      <option value="pencil_pleat" selected="selected">pencil pleat</option>
      <option value="tab_tops">tab tops</option>
      <option value="gathered">gathered </option>
   </select>
</form>
<form id="form4" name="form4" method="post" action="">
   <label for="Type">Type</label>
   <select name="m_pair" id="m_pair">
      <option value="single" selected="1">single</option>
      <option value="pair">pair</option>
   </select>
</form>
<form method="post" action="{$customizationFormTarget}" enctype="multipart/form-data" id="customizationForm" class="clearfix">
   <p class="infoCustomizable">
      {l s='After saving your customized product, remember to add it to your cart.'}
   </p>
   {if $product->text_fields|intval}
   <div class="customizableProductsText">
      <h3>{l s='Please enter dimensions for price calculations:'}</h3>
      <ul id="text_fields">
         {counter start=0 assign='customizationField'}
         {foreach from=$customizationFields item='field' name='customizationFields'}
         {if $field.type == 1}
         <li class="customizationUploadLine{if $field.required} required{/if}">
            <label for ="textField{$customizationField}">{assign var='key' value='textFields_'|cat:$product->id|cat:'_'|cat:$field.id_customization_field} {if !empty($field.name)}{$field.name}{/if}{if $field.required}<sup>*</sup>{/if}</label>
            <textarea name="textField{$field.id_customization_field}" id="textField{$customizationField}" rows="1" cols="40" class="customization_block_input">{if isset($textFields.$key)}{$textFields.$key|stripslashes}{/if}</textarea>
         </li>
         {counter}
         {/if}
         {/foreach}
      </ul>
   </div>
   {/if}
   <p id="customizedDatas">
      <input type="hidden" name="quantityBackup" id="quantityBackup" value="" />
      <input type="hidden" name="submitCustomizedDatas" value="1" />
      <input type="button" class="button" value="{l s='Save'}" onclick="javascript:saveCustomization()" />
      <span id="ajax-loader" style="display:none"><img src="{$img_ps_dir}loader.gif" alt="loader" /></span>
   </p>
</form>
<script type="text/javascript">
   $('#m_heading').on('change', function() {
   if ($(this).val() == 'pencil_pleat'){ $("#group_1").val("1").change(); }
   else if ($(this).val() == 'tab_tops'){ $("#group_1").val("2").change(); }
   else if ($(this).val() == 'gathered'){ $("#group_1").val("3").change(); }
   });

</script> 
<script type="text/javascript">
   $('#m_pair').on('change', function() {               
   if ($(this).val() == 'pair'){ 
   $ilosc_pair = $('#quantity_wanted').val();
   $ilosc_pair = $ilosc_pair * 2;
   $("#quantity_wanted").val($ilosc_pair).change();
   $("#group_5").val("35").change();   
   //           alert("Your quantity has been doubled and your order marked as pair");
   }
   else if ($(this).val() == 'single'){ $("#group_5").val("34").change(); }
   });

</script>