如何使用jQuery在选择框中设置双引号值

时间:2019-04-23 08:13:47

标签: jquery

我想使用jquery将先前从数据库中选择的值显示给select选项。

我的值是40“ X48”。 我使用的代码

    <?php $pallets_type = 40"X48"; ?>
    var pallets_type = "<?=htmlentities($pallets_type);?>";
    $('select[name=pallets_type]').val(pallets_type);

但这对我不起作用。

1 个答案:

答案 0 :(得分:0)

在单引号中添加双引号,例如:

$pallets_type = '40"X48"'; 
var pallets_type = "<?=htmlentities($pallets_type);?>";
$('select[name=pallets_type]').append('<option>"'+pallets_type+'"</option>');