Javascript 如何将数组打印到html文本框
我在JavaScript函数中得到一个响应,它包含一个名为order\u quantity的数组。我需要以相同的顺序将此数组打印到ui中Javascript 如何将数组打印到html文本框,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我在JavaScript函数中得到一个响应,它包含一个名为order\u quantity的数组。我需要以相同的顺序将此数组打印到ui中 <td><input style="width:100px;" type="text" for="order_quantity" id="qty_<?php echo $i;?>" name="order_quantity[]" class="qty number" ></td> 您只需在数组中循环并将数据
<td><input style="width:100px;" type="text" for="order_quantity" id="qty_<?php echo $i;?>" name="order_quantity[]" class="qty number" ></td>
您只需在数组中循环并将数据附加到某个html元素。例如(使用jQuery)
$。每个(订单数量[],功能(键,值){
$(“#myContainerDiv ul”)。追加(“”+value+” ”);
});
在数组中循环并附加每个value@guradio我希望你明白我在这方面是新手。你能推荐一些好的链接吗?或者使用join()
。这完全取决于您想如何显示这些值。@Rory McCrossan我需要在文本字段中打印这些值。文本字段是lokks,就像ui中的一列。然后显示更多代码。您提到的javascript函数在哪里。您只显示PHP代码。哦,编辑你的问题,不要在评论中粘贴代码。谢谢你的有效回复。你能告诉我更多关于提到的html元素吗。我添加了我以前尝试过的帽子。由于我使用元素,它们自然位于
元素中,我指定它的id应该是myContainerDiv
,因此在html中,您需要
,它将被数组中的每个值填满。
if(valid)
{
ajax("indent/indent_api.php",data,function(response)
{
alert(response);
var result=$.parseJSON(response);
var array = response;
//var newHTML = [];
//rder_quantity = [];
$.each(array, function(index, value) {
order_quantity.push('<span>' + value + '</span>');
});
$(".element").html(order_quantity.join(""));
$.each(order_quantity[], function(key, value){
$("#myContainerDiv ul").append("<li>"+value+"</li>");
});