简体   繁体   English

在输入表单中插入值

[英]insert value in input form

When one image is selected...选择一张图像时...

 <div class="selectable"> <img src="https://glarza.com/imagens/tamanho-33.webp" class="ui-widget-content"value="SIZE-33"width="60"height="60"> <img src="https://glarza.com/imagens/tamanho-34.webp" class="ui-widget-content"value="SIZE-34"width="60"height="60"> </div>

this function select the size...这个 function select 尺寸...

 <script> $(function() { $(".selectable").selectable({ selected: function() { var selectedItemList = $("#medida-selecionada-dalista").empty(); $(".selectable img").each(function(index) { if ($(this).hasClass("ui-selected")) { selectedItemList.append( $(this).attr("value") ); } });}});}); </script>

And show the selected size inside the id...并在 id 内显示所选尺寸...

 <span id="medida-selecionada-dalista"></span>
My problem... I need to insert this value inside this input. 我的问题...我需要在这个输入中插入这个值。 I need only this. 我只需要这个。 The others inputs are storeged in mysql. 其他输入存储在 mysql 中。

 <input type="size" class="form-control" id="size" name="size" value="">

Like so?像这样?

 $(function() { $(".selectable").selectable({ selected: function() { var selectedItemList = $("#medida-selecionada-dalista").empty(); $(".selectable img").each(function(index) { if ($(this).hasClass("ui-selected")) { selectedItemList.append( $(this).attr("value") ); /* insert into input */ document.getElementById("size").value = this.getAttribute("value"); } }); } }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <input type="size" class="form-control" id="size" name="size" value=""> <span id="medida-selecionada-dalista"></span> <div class="selectable"> <img src="https://glarza.com/imagens/tamanho-33.webp" class="ui-widget-content" value="SIZE-33" width="60" height="60"> <img src="https://glarza.com/imagens/tamanho-34.webp" class="ui-widget-content" value="SIZE-34" width="60" height="60"> </div>

PS avoid jquery whenever you can... PS尽可能避免jquery...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM