我在MAC上使用
运行Apache$ apachectl start
index.html位于/ Library / WebServer / Documents
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>blah</title>
</head>
<body>
<p>test html file: hello world</p>
<button type="button" name="button" action="contact.php">Press me</button>
</body>
</html>
该页面在浏览器的端口80显示。
按下按钮时应该调用contact.php文件,这个简单回显一个字符串。但是我应该在哪里能够看到这个字符串,以便能够检查contact.php是否正在按预期调用并运行?
contact.php
<?php
echo "blah1234567890";
?>
谢谢,
答案 0 :(得分:1)
你可以使用:
<form action="contact.php">
<input type="submit" value="Press me">
</form>
而不是:
<button type="button" name="button" action="contact.php">Press me</button>
在index.html
文件中。
使用formaction
属性,您可以为一个表单指定多个提交网址。由于表单元素不再需要action属性,因此您可以在提交按钮的formaction
中定义提交URL。提交form
后,浏览器会首先检查formaction
属性;如果不存在,则继续在表单元素上查找action属性。
答案 1 :(得分:1)
action
不是html5中button
元素的有效属性。
以下是使用onclick
属性使按钮像链接一样(如果这是您要实现的目标)的一个选项:
<button type="button" name="button" onclick="window.location.href='contact.php';">Press me</button>