如何正确使用这些 CakePHP 函数作为 Javascript 字符串
for (i = 0; i < filesinput.files.length; i++){
let row_i = document.createElement('tr');
let row_i_data_1 = document.createElement('td');
row_i_data_1.innerHTML = '<?php $this->Form->control("submittedfiles[' + i + '][description]", ['type'=>'text', 'value'=>$file['name'], 'label'=>'']); ?>'
let row_i_data_2 = document.createElement('td');
row_i_data_2.innerHTML = '<?php $this->Form->control("submittedfiles['+i+'][date]", ['type'=>'datepicker', 'default'=>Cake\I18n\Time::now(), 'label'=>'']); ?>';
let row_i_data_3 = document.createElement('td');
row_i_data_3.innerHTML = '<?php $this->Form->control("submittedfiles['+i+'][time]", ['label'=>'', 'type'=>'text', 'default' => date('H:i')]); ?>';
row_i.appendChild(row_i_data_1);
row_i.appendChild(row_i_data_2);
row_i.appendChild(row_i_data_3);
tbody.appendChild(row_i);
}
当在文件输入中选择文件时,我试图生成一个包含输入的表。表生成工作正常,但我无法让字符串接受 php 代码。 包含的代码在编译时会转换为 html 形式,而 JavaScript 不应该有 HTML 作为字符串的问题,所以我不明白这里出了什么问题。
for (i = 0; i < filesinput.files.length; i++){
let row_i = document.createElement('tr');
let row_i_data_1 = document.createElement('td');
row_i_data_1.innerHTML = '<?php $this->Form->control("submittedfiles[' + i + '][description]", ['type'=>'text', 'value'=>$file['name'], 'label'=>'']); ?>'
let row_i_data_2 = document.createElement('td');
row_i_data_2.innerHTML = '<?php $this->Form->control("submittedfiles['+i+'][date]", ['type'=>'datepicker', 'default'=>Cake\I18n\Time::now(), 'label'=>'']); ?>';
let row_i_data_3 = document.createElement('td');
row_i_data_3.innerHTML = '<?php $this->Form->control("submittedfiles['+i+'][time]", ['label'=>'', 'type'=>'text', 'default' => date('H:i')]); ?>';
row_i.appendChild(row_i_data_1);
row_i.appendChild(row_i_data_2);
row_i.appendChild(row_i_data_3);
tbody.appendChild(row_i);
}
I'm trying to generate a table with inputs when files are selected in the filesinput. The table generation works, but I'm having trouble with getting the strings to accept the php code. The code enclosed by <?php ?>
gets converted to html forms when compiling, and JavaScript shouldn't have a problem with HTML as strings, so I don't understand what's going wrong here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论