我有一个php变量。然后在按钮上单击JS,我必须打开一个包含该变量的链接。根据其他主题,这必须起作用,但事实并非如此。如果单击它,什么也不会发生。
<?php
$id = 'string';
?>
<SCRIPT language="JavaScript">
function openBox() {
php_var = <?php echo $id; ?>;
targetURL = "other_page.php?id=" + php_var
theBox = window.open(targetURL, 'theResults', 'status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=0, scrollbars=1, width=600,height=680,left=10,top=10');
}
</SCRIPT>
*编辑:好了,我忘了var
,'
和;
。修改后的代码(如下)现在可以打开所需的站点,但是var为空。如果我只是在php中回显它,那么它就很有价值。
<?php
$id = 'string';
?>
<SCRIPT language="JavaScript">
function openBox() {
php_var = '<?php echo $id; ?>';
targetURL = "other_page.php?id=" + php_var
theBox = window.open(targetURL, 'theResults', 'status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=0, scrollbars=1, width=600,height=680,left=10,top=10');
}
</SCRIPT>
代表OP张贴。
解决方案:我有html扩展名而不是php,因此尚未执行php代码。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句