Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.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动态添加选择框_Javascript_Jquery_Html - Fatal编程技术网

Javascript 使用JQuery动态添加选择框

Javascript 使用JQuery动态添加选择框,javascript,jquery,html,Javascript,Jquery,Html,我有一些在订单确认屏幕上打印客户订单的代码。它使用Javascript将信息填充到表中。理想情况下,我希望在JQuery 这是我的HTML <!-- Order Confirmation Form --> <form action="<?the_permalink()?>" method="post"> <div id="summary"> <table id="ordertable"> <

我有一些在订单确认屏幕上打印客户订单的代码。它使用
Javascript
将信息填充到
表中。理想情况下,我希望在
JQuery

这是我的
HTML

 <!-- Order Confirmation Form -->
    <form action="<?the_permalink()?>" method="post">
    <div id="summary">
    <table id="ordertable">
        <tr><th>Product</th>
        <th>Quantity</th>
        <th>Bulk</th>
        <th>Options</th>
        </tr>
    </table>
    <!-- Comments Box -->
    Comments<br/>
    <textarea name="comments"></textarea><br/>
    <input name="product_list" id="products_field" type="hidden" value="<?= isset($_POST['product_list'])?$_POST['product_list']:'' ?>">
    Next Day Delivery <input type="checkbox" name="next-day-delivery" value="yes" />
    <input type="submit" value="Confirm Order" class="confirmBtn"/>
    </div>
    </form>
这是我的页面图像,我似乎不知道如何在
bulk
下面的单元格中添加
select
框(用红色标出)。如果
bulk==true
显示
选择框
else
则不显示任何内容。(有些产品可以批量订购。)


有人对我如何实现这一目标有什么建议吗

可能只是像

if(productArray[i].bulk)
 cell3.innerHTML =  "<select><option>1</option>..</select>";
if(productArray[i].bulk)
cell3.innerHTML=“1..”;
像这样试试

 cell3.innerHTML = (productArray[i].bulk)?'<select><option value="...">...</option></select>':'';
cell3.innerHTML=(productArray[i].bulk)?“…”:”;
试试这个

var select = '<select><option value="1">1</option><option value="2">2</option></select>';
cell3.innerHTML = productArray[i].bulk?select: '';
var select='12';
cell3.innerHTML=productArray[i]。批量?选择:“”;
或者只是

cell3.innerHTML = productArray[i].bulk? '<select><option value="1">1</option><option value="2">2</option></select>' : '
cell3.innerHTML=productArray[i]。批量12' : '
for(var i=0;i
在代码中没有使用
jQuery
。请重新标记您的问题。@MelanciaUK可能是为了表明jQuery解决方案受欢迎。@TJ没错,我被告知我的代码应该在
jQuery
中,显然在上面它在
JS
中,但我愿意接受关于如何实现该解决方案的任何建议。此外,不管是谁否决了这个问题,你能告诉我为什么吗?我不认为这是一个结构拙劣的问题,我已经尽一切努力使问题尽可能清楚。哇。。!和我的完全不同。甚至点的数量!
cell3.innerHTML = productArray[i].bulk? '<select><option value="1">1</option><option value="2">2</option></select>' : '
for(var i = 0; i < productArray.length; i ++){

        //This is the data to display
        console.log("Order Item " + i);
        console.log("StockCode: " + productArray[i].stockCode);
        console.log("Quantity: " + productArray[i].quantity);
        console.log("Bulk: " + productArray[i].bulk);

        var row = ordertable.insertRow(i + 1);
        var cell1 = row.insertCell(0);
        var cell2 = row.insertCell(1);
        var cell3 = row.insertCell(2);
        var cell4 = row.insertCell(3);
        cell1.innerHTML = productArray[i].stockCode;
        cell2.innerHTML = productArray[i].quantity;
        if(productArray[i].bulk) // true means select
        cell3.innerHTML = "<select><option>1</option>..</select>"
        else
        cell3.innerHTML = '';
        ell4.innerHTML = "<input type='button' value='-' class='removeBtn'/><input type='button' value='+' class='addBtn'/><input type='button' value='Delete' class='deleteBtn'/>"
    }