【问题标题】:How to create a HTML canvas via form如何通过表单创建 HTML 画布
【发布时间】:2014-09-11 23:12:37
【问题描述】:

我想从用户那里获取画布的大小。当用户给出特定的像素大小时,画布将被绘制为该大小。我正在尝试运行此代码,但它不工作。我试图得到它通过表单和 PHP 中定义的值.. 这两种方式都不起作用..

<html>
<body style=" background: lightblue;">

<?php

//@$height=['$height'];
//@$width=['$width'];

$h=420;
$w=420;

?>


<center>
<form name="test" action="Untitled-1.php"> 
Please enter height : <input type="text" name="height"> <br>
Please enter widht : <input type="text" name="width"> <br>
<input type="submit" value="submit" name="submit"> <br>
</form>
</center>

<!-- <canvas id="canvas" width="420px" height="420px" style="background: #fff; magrin:20px;"> -->
<canvas id="canvas" height=<?php '".$h."' ?> width=<?php '".$w." '?> Style="background: #fff;">
<!-- <canvas id="canvas" height=<?php '".$height."' ?> width=<?php '".$width." '?> Style="background: #fff;"> -->

Browser does not support canvas 
</canvas>
</body>
</html>

【问题讨论】:

  • 你需要在画布标签中回显你的 php 变量:&lt;?php echo $h; ?&gt;

标签: php html canvas


【解决方案1】:

您没有在 PHP 中打印输出。

替换

<canvas id="canvas" height=<?php '".$h."' ?> width=<?php '".$w." '?> Style="background: #fff;">

<canvas id="canvas" height="<?= $h; ?>" width="<?= $w; ?>" Style="background: #fff;">

如果也不起作用,则说明您没有启用 short_open_tag,因此请将 &lt;?= 替换为 &lt;?php echo

【讨论】:

    【解决方案2】:

    你可以使用这个表达式:

    <?php echo '<canvas id="canvas" height='.$h.'  width='.$w' Style="background: #fff">'; ?>
    

    【讨论】:

      猜你喜欢
      • 2015-09-26
      • 2011-03-17
      • 2013-05-19
      • 1970-01-01
      • 1970-01-01
      • 2021-09-12
      • 1970-01-01
      • 2023-02-18
      • 2022-08-18
      相关资源
      最近更新 更多