简体   繁体   English

如何使整个Div成为按钮?

[英]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变量,并将其回显。

我怎么做<div>单击按钮时部分不可见(JS)?</div><div id="text_translate"><p> 如何使用 JS 隐藏&lt;div&gt;部分和</p><pre>&lt;div class="alertB1"&gt; &lt;div class="sticky"&gt; &lt;h1&gt; This site is still being built&lt;/h1&gt; &lt;p&gt; Please remember this site is still being built. Click &lt;a href="form1.html"&gt;here to report a bug &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;style&gt;.sticky { position: -webkit-sticky; position: sticky; }.alertB1 { width: 100%; height: 125px; background: lightgreen; } &lt;/style&gt;</pre><p> 所以我希望包含一个按钮:</p><pre> &lt;span id="a33"&gt;&lt;button&gt;&amp;times;&lt;/button&gt;&lt;/span&gt; &lt;/div&gt; &lt;/div&gt;</pre><p> 如何让&lt;span&gt;隐藏&lt;div&gt;标签? 谢谢,环形游戏</p></div> - How do i make a <div> section invisible when a button is clicked (JS)?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我该如何做 <div> 单击按钮时滑入视图? - How Do I make a <div> slide into view when a button is clicked? 如何使整个div可点击 - How to make the whole div clickable 如何使整个 div 可点击? - How to make the whole div clickable? 如何为某个 div(而不是整个页面)运行 queryCommandState? - How do I run queryCommandState for a certain div (and not the whole page)? 如何在不刷新整个页面的情况下使用AJAX刷新div? - How do I refresh a div with AJAX without refreshing the whole page? 如何删除div中的最后一个html行? - How do I remove the whole last html line in div? 我怎么做<div>单击按钮时部分不可见(JS)?</div><div id="text_translate"><p> 如何使用 JS 隐藏&lt;div&gt;部分和</p><pre>&lt;div class="alertB1"&gt; &lt;div class="sticky"&gt; &lt;h1&gt; This site is still being built&lt;/h1&gt; &lt;p&gt; Please remember this site is still being built. Click &lt;a href="form1.html"&gt;here to report a bug &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;style&gt;.sticky { position: -webkit-sticky; position: sticky; }.alertB1 { width: 100%; height: 125px; background: lightgreen; } &lt;/style&gt;</pre><p> 所以我希望包含一个按钮:</p><pre> &lt;span id="a33"&gt;&lt;button&gt;&amp;times;&lt;/button&gt;&lt;/span&gt; &lt;/div&gt; &lt;/div&gt;</pre><p> 如何让&lt;span&gt;隐藏&lt;div&gt;标签? 谢谢,环形游戏</p></div> - How do i make a <div> section invisible when a button is clicked (JS)? 我怎么做 <div> 进入 <textarea> 单击“输入键盘按钮”时是否也要复制换行符? - How do I make <div> into <textarea> copy to copy the line break too when hitting “enter keyboard button”? 单击按钮时如何缩短所有div框? - How do I make all div boxes shorten when a button is clicked? 如何使容器充满整个页面? 也要回应 - How do I make a container fill the whole page? Also to be responsive
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM