[英]How I can add php function in style.js file?
This code perfect work if it writes in the same PHP file.如果它写入同一个 PHP 文件,则此代码完美工作。 But if I write a script in my
style.js
file and then call in PHP script src="style.js"
then select option does not work.但是,如果我在
style.js
文件中编写脚本,然后调用 PHP 脚本src="style.js"
则 select 选项不起作用。 It looks like js file does not accept PHP code:看起来 js 文件不接受 PHP 代码:
function account_number($sel_acc){
$output = '';
foreach($sel_acc as $row){
$output .= '<option value="'.$row["NominalAccount"].'">'.$row["NominalAccount"].' ' .$row["NominalName"].'</option>';
}
return $output;
}
var count = $(".itemRow").length;
$(document).on('click', '#addRow', function(){
count++;
var htmlRows = '';
htmlRows += '<tr>';
htmlRows += '<td><select type="text" id="idAccounts'+count+'" name="idAccounts[]"><option value="4000">4000</option><?php echo account_number($sel_acc); ?></selected></td>';
htmlRows += '</tr>';
$("#inv_sale_detail").append(htmlRows);
});
The problem might be here:问题可能在这里:
?></selected></td>
The closing tag should be </select>
At the end of that line.结束标记应该是
</select>
在该行的末尾。 And the select input does not accept the attribute type
Where you have written type="text"
并且 select 输入不接受属性
type
你写的地方type="text"
Second: When you input <?php... ?>
tags in any other file other than a php
file that has the extension .php
, it will be parsed as a string and will not produce the result as it would from a php
file Second: When you input
<?php... ?>
tags in any other file other than a php
file that has the extension .php
, it will be parsed as a string and will not produce the result as it would from a php
file
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.