[英]How do I make a whole Div a Button?
First I made a link of the whole div 首先,我做了整个div的链接
<a href=''><div></div></a>
Its clickable and everything but with this I cant Submit a POST which I want to do so im trying to make the whole div a button(and then make it transparent) But the button doesnt fill the whole div and the buttons placement aint in the whole div but outside the div. 它的可点击性以及其他所有内容,但是与此相关,我无法提交POST,我想这样做是试图将整个div设置为一个按钮(然后使其透明),但是该按钮无法填充整个div,并且按钮放置在整个区域中股利,但股利之外。
<button><div></div></button>
How do I make the WHOLE div a button? 如何将整个div设为按钮?
@Rodrigo Leite @罗德里戈·莱特
if(isset($_POST['submit'])){
//test
header("Location: http://www.google.com/");
}
<script language="JavaScript" type="text/javascript" src="/js/jquery-1.2.6.min.js"></script>
<script language="JavaScript" type="text/javascript" src="/js/jquery-ui-personalized-1.5.2.packed.js"></script>
<script language="JavaScript" type="text/javascript" src="/js/sprinkle.js"></script>
<script>
$(document).ready(function(){
$('#div_test').click(function(){
$('#form').submit();
});
});
</script>
<form name='form' action='' method='POST'><div id='div_test' ></div></form>
You can do this, using javascript: 您可以使用javascript来做到这一点:
<?php
$name = @$_POST['name'];
$lastName = @$_POST['lastName'];
echo 'Received data:<br>';
echo $name . ' ' . $lastName;
echo '<br><br>';
?>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
<form action='' method='post' id='form'>
Name: <input type='text' name='name'><br>
Last name: <input type='text' name='lastName'<br>
<br><br>
<div onclick='$("#form").submit();' style='border: 1px solid #000000'>
DIV example: Fire form submit on click</div>
</div>
<br><br>
<input type='submit' value='Submit butto e.g.'>
</form>
<body>
</html>
I hope it helps you. 希望对您有帮助。
In order to make a post to a page you will need a form that has the post method. 为了发布到页面,您将需要一个具有post方法的表单。
index.html index.html
<form action="action_page.php" id="myNames" method="post">
First name:<br>
<input type="text" name="myName">
<br>
Last name:<br>
<input type="text" name="myLastName">
<br><br>
<input type="submit" value="Submit">
</form>
Then recieve the information that is posted by a php
file. 然后接收由
php
文件发布的信息。
action_page.php action_page.php
$firstName = $_POST['myName'];
$lastName = $_POST['myLastName'];
echo $firstName . ' ' . $lastName;
To submit a form with javascript
用
javascript
提交表单
<div class="button" id="SubmitForm" onclick="submitForm()" title="myNames">
function submitForm()
{
document.getElementById('myNames').submit();
}
Now when you click the div with the id="SubmitForm"
the for, will be submitted. 现在,当您单击带有
id="SubmitForm"
的div时,将提交。 Notice the id of each element. 注意每个元素的ID。 This is how we are selecting each element.
这就是我们选择每个元素的方式。
Then with our php when we get to the php page we use the name of each element to convert to a php variable and echo it back. 然后使用我们的php,当我们进入php页面时,我们使用每个元素的名称转换为php变量,并将其回显。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.