Onclick按钮在HTML文件中工作,但不能在PHP文件中的HTML中工作(Onclick of button works in HTML file but does not work in HTM

编程入门 行业动态 更新时间:2024-10-28 15:34:52
Onclick按钮在HTML文件中工作,但不能在PHP文件中的HTML中工作(Onclick of button works in HTML file but does not work in HTML inside a PHP file)

我对PHPJSHTML非常陌生 ,所以我希望你不要介意这个问题是否很微不足道。 所以我基本上有下面的代码, onlick会在一个单独的HTML文件中工作,但如果我把它放在一个PHP文件的回声中,或者把它放在一个PHP文件中的一个单独的html块中,它将不起作用。

button.html(这个工程)

<body> <p>Click the button to display the time.</p> <button onclick="getElementById('demo').innerHTML=Date()">What is the time?</button> <p id="demo"> </p> </body> </html>

这里是回声代码:

button.php(不起作用)

<?php .... .... echo " <input type ='button' value = 'Date' onclick = 'getElementById('demo')=Date();' /> <p id='demo'> </p> " ?>

这是PHP文件中的HTML代码不起作用。

button.php(不起作用)

<?php> ?> <html> <body> <p>Click the button to display the time.</p> <button onclick="getElementById('demo').innerHTML=Date()">What is the time?</button> <p id="demo"></p> </body> </html>

任何帮助,将不胜感激!

I'm very new to PHP, JS, and HTML so I hope you don't mind if the question is very trivial. So I basically have the following code, the onlick would work in a separate HTML file but it will not work if I put this in an echo of a PHP file or put it in a separate html block inside a PHP file.

button.html (this works)

<body> <p>Click the button to display the time.</p> <button onclick="getElementById('demo').innerHTML=Date()">What is the time?</button> <p id="demo"> </p> </body> </html>

Here is the echo code:

button.php (doesn't work)

<?php .... .... echo " <input type ='button' value = 'Date' onclick = 'getElementById('demo')=Date();' /> <p id='demo'> </p> " ?>

This is the HTML code inside PHP file that doesn't work.

button.php (doesn't work)

<?php> ?> <html> <body> <p>Click the button to display the time.</p> <button onclick="getElementById('demo').innerHTML=Date()">What is the time?</button> <p id="demo"></p> </body> </html>

Any help would be appreciated!

最满意答案

这是我已经试过希望这有助于

<!DOCTYPE html>
<html>
<body>

<h1>My First JavaScript</h1>

<button type="button"
onclick="document.getElementById('date_time_button').innerHTML = Date()">
Click and see Date and Time.</button>

<p id="date_time_button"></p>

</body>
</html>  
  
 

This is what i have tried Hope this helps

<!DOCTYPE html>
<html>
<body>

<h1>My First JavaScript</h1>

<button type="button"
onclick="document.getElementById('date_time_button').innerHTML = Date()">
Click and see Date and Time.</button>

<p id="date_time_button"></p>

</body>
</html>  
  
 

更多推荐

HTML,PHP,button,电脑培训,计算机培训,IT培训"/> <meta name="description&q

本文发布于:2023-07-29 15:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1317544.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   工作   能在   但不   按钮

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!