Cakephp表单助手无法在jQuery附录中工作

时间:2019-05-15 06:18:20

标签: cakephp cakephp-3.x

我试图将div附加到append中,但我总是得到SyntaxError: missing ) after argument list

我的div看起来像

<div class='col-md-6'>
     <div class='form-group'>
          <?= $this->Form->control('user_id', ['options' => $users,'class'=>'form-control']);?>
      </div>
     <div class='form-group'>
           <?= $this->Form->control('phone_number',['class'=>'form-control']); ?>
     </div>              
</div>

我尝试了如下所示的追加

$('#cform').append("<div class='col-md-6'><div class='form-group'><?= $this->Form->control('user_id', ['options' => $users,'class'=>'form-control']);?></div><div class='form-group'><?= $this->Form->control('phone_number',['class'=>'form-control']); ?></div></div>");

我在这里没有任何语法错误,如何解决呢?

1 个答案:

答案 0 :(得分:0)

您可以使用反勾`

$('#cform').append(`<div class='col-md-6'><div class='form-group'><?= $this->Form->control('user_id', ['options' => $users,'class'=>'form-control']);?></div><div class='form-group'><?= $this->Form->control('phone_number',['class'=>'form-control']); ?></div></div>`);

IE中可能不支持反勾号,因此可以在空格前使用“ \”

示例:

<div class="form-group">\
  <?= $this->Form->control('user_id', ['options' => $users,'class'=>'form-control']);?>\
</div>\
<div class="form-group">\
<?= $this->Form->control('phone_number',['class'=>'form-control']); ?>\
</div>\