所以我有一个表单需要post
数据到隐藏的div我想在表单submitted
时显示,所以当用户点击submit
时需要show
div和posted results
<div id="lootnumbers">
<form method="post" name="lootNumber" onsubmit="show(); return false;">
Choose your 2 lucky numbers!
<input type="number" name="quantity1" min="1" max="5" /><br>
<input type="number" name="quantity2" min="1" max="5" /><br>
<input type="submit" value="submit" name="submit" />
</form>
</div>
<div id="loot_dice" style="display:none;">
<?php $first = $_POST['quantity1'];
$second= $_POST['quantity2'];
echo $first;
echo $second;
?>
<div id="die2" class="dice">0</div>
<button id="roll" onclick="rollLoot();">Roll Dice</button>
</div>
和js文件
function show() {
var div = document.getElementById("loot_dice");
if (div.style.display == 'none') {
div.style.display = '';
} else {
div.style.display = 'none';
}
}
问题是它确实在提交时显示div,但它不会发布/显示结果(我尝试使用隐藏/显示div所在的form action 'index.php
(表单也位于index.php中)
答案 0 :(得分:1)
试试这个:
<div id="lootnumbers">
<form method="post" name="lootNumber" action="">
Choose your 2 lucky numbers!
<input type="number" name="quantity1" min="1" max="5" /><br>
<input type="number" name="quantity2" min="1" max="5" /><br>
<input type="submit" value="submit" name="submit" />
</form>
</div>
<?php $style=""; if(empty($_POST)) { $style = 'display:none;'; } ?>
<div id="loot_dice" style="<?php echo $style; ?>">
<?php
if(!empty($_POST)) {
$first = $_POST['quantity1'];
$second= $_POST['quantity2'];
echo $first;
echo $second;
}
?>
<div id="die2" class="dice">0</div>
<button id="roll" onclick="rollLoot();">Roll Dice</button>
</div>
答案 1 :(得分:0)
这是因为您的文档具有内联样式。也许你的函数正在显示它,但是当表单被提交并且页面被重新加载时,它会再次变得不可见。
您可以尝试以下内容:
<div id="loot_dice" style="display:<?= if(isset($_POST['quantity1'])) ? 'block' : 'none' ?>;">
或者,就像@Bikash对你说的那样,尝试类似ajax或jQuery来实现它。
答案 2 :(得分:0)
也许你的意思是
private void getBytes()
{
int numBytes = bitsPerSample / 8; //Number of bytes depending the tiff map
int stride = numBytes * height;
byte[] bufferTiff = new byte[stride * height]; // this is the buffer with the tiles data
int offset = 0;
for (int i = 0; i < tif.NumberOfTiles() - 1; i++)
{
int rawTileSize = (int)tif.RawTileSize(i);
offset += tif.ReadEncodedTile(i, bufferTiff, offset, rawTileSize);
}
values = new double[height, width]; // this is the matrix to save the heigth values in meters
int ptr = 0; // pointer for saving the each data bytes
int m = 0;
int n = 0;
byte[] byteValues = new byte[numBytes]; // bytes of each height data
for (int i = 0; i < bufferTiff.Length; i++)
{
byteValues[ptr] = bufferTiff[i];
ptr++;
if (ptr % numBytes == 0)
{
ptr = 0;
if (n == height) // tiff map Y pixels
{
n = 0;
m++;
if (m == width) // tiff map X pixels
{
m = 0;
}
}
values[m, n] = BitConverter.ToDouble(byteValues, 0); // Converts each byte data to the height value in meters. If the map is 32 bps the method I use is BitConverter.ToFloat
if (n == height - 1 && m == width - 1)
break;
n++;
}
}
SaveArrayAsCSV(values, "values.txt");
}
//Only to show results in a cvs file:
public void SaveArrayAsCSV(double[,] arrayToSave, string fileName) // source: http://stackoverflow.com/questions/8666518/how-can-i-write-a-general-array-to-csv-file
{
using (StreamWriter file = new StreamWriter(fileName))
{
WriteItemsToFile(arrayToSave, file);
}
}
//Only to show results in a cvs file:
private void WriteItemsToFile(Array items, TextWriter file) // source: http://stackoverflow.com/questions/8666518/how-can-i-write-a-general-array-to-csv-file
{
int cont = 0;
foreach (object item in items)
{
if (item is Array)
{
WriteItemsToFile(item as Array, file);
file.Write(Environment.NewLine);
}
else {
file.Write(item + " | ");
cont++;
if(cont == width)
{
file.Write("\n");
cont = 0;
}
}
}
}