在选项标记中的jQuery中嵌入PHP代码
单击按钮时动态生成一个下拉列表,当在中创建下拉列表时,在选项标记中显示产品表中的产品数据。那么,如何在jQuery的选项标记中嵌入PHP代码呢 这是我生成下拉列表的代码:在选项标记中的jQuery中嵌入PHP代码,php,jquery,Php,Jquery,单击按钮时动态生成一个下拉列表,当在中创建下拉列表时,在选项标记中显示产品表中的产品数据。那么,如何在jQuery的选项标记中嵌入PHP代码呢 这是我生成下拉列表的代码: jQuery(document).ready(function ($) { $('.my-form .add-box').click(function () { var n = $('.text-box').length + 1; var box_html = $('<p clas
jQuery(document).ready(function ($) {
$('.my-form .add-box').click(function () {
var n = $('.text-box').length + 1;
var box_html = $('<p class="text-box"><label>Product: </label><select name="boxes[]" value="" id="box' + n + '" style="width:450px; height:40px;"><option>Select Product</option></select> <a href="#" class="remove-box btn btn-danger">Delete</a><br><br></p>');
box_html.hide();
$('.my-form p.text-box:last').after(box_html);
box_html.fadeIn('slow');
return false;
});
$('.my-form').on('click', '.remove-box', function () {
$(this).parent().fadeOut("slow", function () {
$(this).remove();
$('.box-number').each(function (index) {
$(this).text(index + 1);
});
});
return false;
});
jQuery(文档).ready(函数($){
$('.my form.add box')。单击(函数(){
var n=$('.text box')。长度+1;
var box_html=$('产品:选择产品
);
box_html.hide();
$('.my form p.text-box:last')。在(box_html)之后;
box_html.fadeIn('slow');
返回false;
});
$('.my form')。在('单击','.remove box',函数(){
$(this).parent().fadeOut(“慢”,函数(){
$(this.remove();
$('.box number')。每个(函数(索引){
$(此).text(索引+1);
});
});
返回false;
});
我已经这样做了:
<div class="my-form">
<p class="text-box">
<label>Product: </label>
<select id="box1" class="email" name="box[]" style="width:450px; height:40px;">
<option value="">Select Product</option>
<?php
while ($row = mysql_fetch_array($result))
{
?>
<option value="<?php echo $row['product_id']; ?>"><?php echo $row['product_name']; ?></option>
<?php
}
?>
</select>
<a class="btn btn-success addmore add-box"> Add Product </a><br><br>
</p>
</div>
产品:
精选产品
添加产品
下拉列表也是动态生成的,但问题在于选项标签中的jQuery代码如何应用上面的php代码来显示我不知道的产品名称您要嵌入的php代码是什么,在哪里?我想在下拉列表中显示的产品名称。我已经用这种方式创建了一个下拉列表,但当我再次单击按钮时在创建一个下拉列表的过程中,也完成了,但是上面的代码我想嵌入到jqury中,我不知道。不要把代码放在注释中,编辑问题。可能最好让PHP将选项放在HTML中,并用CSS隐藏它们。然后jQuery可以对该元素调用
.show()
,而不是动态创建它。