隐藏Div的输出没有javascript

时间:2014-04-21 04:55:21

标签: javascript php html

这是java脚本函数。我想让它生成div" resultss"可见并显示输出。

但它没有显示结果,php代码执行没有错误。这是不显示任何输出的。

我试图将结果附加到用户提交一些数据的同一页面的底部

<script>
function myFunction()
{
var e = document.getElementById("resultss");
e.style.display = "block";
<?php

$format =  $_SESSION["ff"];
$ses_id = $_SESSION["id"];
$filena = $_SESSION["filename"];
//$pubquery = $_SESSION["pubquery"];
$result1 = shell_exec("C:\Python27\python.exe C:\Python27\PredictoR\Model_desc.py $format $ses_id $filena  2>&1");
$properties = explode(" ", $result1);
if($properties[0] == 1)
{
$property = "Substrate";
} else  {
$property = "Non-substrate";
}
$molwt = trim(preg_replace('/\s+/', ' ', $properties[1]));
$nhd = trim(preg_replace('/\s+/', ' ', $properties[2]));
$nha = trim(preg_replace('/\s+/', ' ', $properties[3]));
$logp = trim(preg_replace('/\s+/', ' ', $properties[4]));

?>

var molwt = <?php echo json_encode( $molwt); ?>;
var nhd = <?php echo json_encode( $nhd); ?>;
var nha = <?php echo json_encode( $nha); ?>;
var logp = <?php echo json_encode( $logp); ?>;
var property = <?php echo json_encode( $property); ?>;

document.getElementById('properties').innerHTML="Molecule is : "+property+"  \n\
<br/>Molecular weight is : "+molwt+" \n\
<br/>No. of hydrogen bond donors = "+nhd+"\n\
<br/>No. of hydrogen bond acceptors = "+nha+"\n\
<br/>Log P :  = "+logp+";

}

1 个答案:

答案 0 :(得分:0)

首先关闭脚本代码</script> 其次,我看不到你在调用你的函数myFunction()。试试吧。 我希望它有所帮助。

因此,您的代码应该类似于:

<script>
  function myFunction()
  {
    var e = document.getElementById("resultss");
    e.style.display = "block";
<?php
$format = $_SESSION["ff"];
$ses_id = $_SESSION["id"];
$filena = $_SESSION["filename"];
//$pubquery = $_SESSION["pubquery"];
$result1 = shell_exec("C:\Python27\python.exe C:\Python27\PredictoR\Model_desc.py $format $ses_id $filena  2>&1");
$properties = explode(" ", $result1);
if ($properties[0] == 1) {
  $property = "Substrate";
} else {
  $property = "Non-substrate";
}
$molwt = trim(preg_replace('/\s+/', ' ', $properties[1]));
$nhd = trim(preg_replace('/\s+/', ' ', $properties[2]));
$nha = trim(preg_replace('/\s+/', ' ', $properties[3]));
$logp = trim(preg_replace('/\s+/', ' ', $properties[4]));
?>

    var molwt = <?php echo json_encode($molwt); ?>;
    var nhd = <?php echo json_encode($nhd); ?>;
    var nha = <?php echo json_encode($nha); ?>;
    var logp = <?php echo json_encode($logp); ?>;
    var property = <?php echo json_encode($property); ?>;

    document.getElementById('properties').innerHTML = "Molecule is : " + property + "  \n\
<br/>Molecular weight is : " + molwt + " \n\
<br/>No. of hydrogen bond donors = " + nhd + "\n\
<br/>No. of hydrogen bond acceptors = " + nha + "\n\
<br/>Log P :  = " + logp;

  }
  myFunction();
</script>