[英]How to pass values to a div? Jquery
I have a form below, to pass below values to div (myDiv) and want that div to be shown (display:block).我在下面有一个表格,用于将以下值传递给 div (myDiv) 并希望显示该 div (display:block)。
<form method="post">
<input type="text" name="value_a" value="A" >
<input type="text" name="value_b" value="B" >
<input type="submit" name="submitX" value="submit" ;">
</form>
<div id="myDiv" style="display: none;" >
<?php if(isset($_POST['submitX']))
{
$AA= $_POST['value_a'];
$BB = $_POST['value_b'];
.
.
</div>
I already try below input type:我已经尝试了以下输入类型:
<input type="button" name="submitX" value="Submit" onclick="document.getElementById('myDiv').style.display = 'block' ;" >
It shows the div(myDiv) but the values i wanted not carry along.它显示了 div(myDiv) 但我不想携带的值。
Thanx:)谢谢:)
You assign values to variables, but you never actually output them.你给变量赋值,但实际上你从来没有output他们。 Instead of this:
而不是这个:
$AA= $_POST['value_a'];
Simply do this:只需这样做:
echo $_POST['value_a'];
Additionally, your <div>
should probably be visible in order to see it.此外,您的
<div>
应该是可见的才能看到它。 This is styled to always be hidden:这被设计成总是隐藏的:
<div id="myDiv" style="display: none;" >
Even if you run JavaScript to show it when clicking the button, that won't matter as soon as the form posts and the page reloads.即使您在单击按钮时运行 JavaScript 以显示它,一旦表单发布和页面重新加载,这也无关紧要。 Instead, conditionally style it based on the form input:
相反,根据表单输入有条件地设置样式:
<div id="myDiv" style="display: <?= isset($_POST['submitX']) ? "block" : "none" ?>;" >
Or if you prefer for readability:或者,如果您更喜欢可读性:
<?php if (isset($_POST['submitX'])) { ?>
<div id="myDiv">
<?php } else { ?>
<div id="myDiv" style="display: none;">
<?php } ?>
There are a variety of ways to structure your logic, really.实际上,有多种方法可以构建您的逻辑。
As a learning exercise, further considerations include:作为学习练习,进一步的考虑包括:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.