开发者

how to return javascript in a php class file ?

I want the following javascript code to be echoed in a PHP class file. How I can achieve that?

echo '<script language="JavaScript" type="text/javascript">'."\n";
        echo 'var parDoc = window.parent.document;';
        if ($result == 'OK') {
        echo 'parDoc.getElementById("picture_开发者_开发知识库error").innerHTML =  "";';
        }
        else {
        echo "parDoc.getElementById('picture_error').innerHTML = '".$result_msg."';";
        }

        if($filename != '') {
        echo "parDoc.getElementById('picture_preview').innerHTML = '<img src=\'$preview_url$filename\' id=\'preview_picture_tag\' name=\'preview_picture_tag\' width=\'60\' />';";
        }

        echo "\n".'</script>';
        exit(); // do not go futher


<?php 
?>
<script language="JavaScript" type="text/javascript">
var parDoc = window.parent.document;
<?php
if ($result == 'OK') { 
    ?>       
    parDoc.getElementById("picture_error").innerHTML =  "";
    <?php 
} 
else {
    ?>
     parDoc.getElementById("picture_error").innerHTML = "<?php echo $result_msg;?>";
    <?php
}

if($filename != '') {
      ?>
      parDoc.getElementById("picture_preview").innerHTML = '<img 
                                    src=\'<?php echo $preview_url.$filename;?>\' 
                                    id=\'preview_picture_tag\' 
                                    name=\'preview_picture_tag\' 
                                    width=\'60\' />';
      <?php
        }
       ?>
        </script>
        exit(); // do not go futher


Surround it with the PHP code sequence relevant to your installation: <? ?> or <?php ?> depending on your configuration.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜