[英]What's the better way to generate pdf using javascript and/or php?
[英]What's a better way to call a JavaScript function in another file?
我当时正在做前端工作,为此,我不得不在其他文件中调用各种函数javascript / jQuery。 因此,我将PHP与CodeIgniter结合使用,并且尝试从PHP函数进行调用以调用另一个函数javascrip。
PHP:
public function validaInclusao() {
getAtributoJanelaPai("slCusto");
}
function getAtributoJanelaPai($idCampo) {
carregaScriptsJquery();
echo "getAtributoJanelaPai('$idCampo');";
}
JavaScript:
function getAtributoJanelaPai(idCampo) {
alert('getAtributoJanelaPai');
var element = window.opener.document.getElementById(idCampo);
var value = '';
if (element.tagName === 'SELECT') {
value = element.selectedIndex + '|' + element.options[element.selectedIndex].value;
} else if (element.tagName === 'INPUT') {
value = element.value;
}
alert(value);
}
因此,就像下面这样:
echo "getAtributoJanelaPai('$idCampo');";
您可以这样做,但是必须将Javascript文件导入到文档中。
在您的头部插入以下内容:
<script type="text/javascript" src="myScripts.js"></script>
其中“ myScripts.js”是Javascript文件的文件名。
这就是您执行回显的方式:
<?php echo getAtributoJanelaPai($idCampo); ?>
创建将返回某些内容的javascript文件
function getAtributoJanelaPai(idCampo) {
alert('getAtributoJanelaPai');
var element = window.opener.document.getElementById(idCampo);
var value = '';
if (element.tagName === 'SELECT') {
value = element.selectedIndex + '|' + element.options[element.selectedIndex].value;
} else if (element.tagName === 'INPUT') {
value = element.value;
}
return(value);
}
并在php文件中使用它,首先包含创建的js文件。
public function validaInclusao() {
getAtributoJanelaPai("slCusto");
}
function getAtributoJanelaPai($idCampo) {
carregaScriptsJquery();
echo "<script language=javascript>document.write(getAtributoJanelaPai(idCampo));</script>";
}
或尝试这个
echo "<script language=javascript>getAtributoJanelaPai(idCampo);</script>";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.