我创建了HTML表单,其中一个字段是display
div,它从用户的网络摄像头获取图像,并将其保存为base64_encode,目前仅为#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define M_PI 3.14
void circle(int num, double area, double per) {
area = (double)(M_PI * pow(num, 2));
per = (double)(2 * M_PI * num);
}
void rt(int num, int num1, double area, double per) {
area = (double)(0.5 * num * num1);
per = (double)((num + num1) + sqrt(pow(num, 2) + pow(num1, 2)));
}
void display(char entry, double area, double per) {
if (entry == 'c') {
printf("The circle has area %.1lf and perimeter %.1lf.\n", area, per);
} else {
printf("The right triangle has area %.1lf and perimeter %.1lf.\n", area, per);
}
}
int main() {
char entry;
int num;
int num1;
double area = 0;
double per = 0;
printf("Please enter 'c' for a circle or 't' for a right triangle\n");
scanf("%c", &entry);
if (entry == 'c') {
printf("Please enter the radius for the circle.\n");
scanf("%d", &num);
getchar();
circle(num, area, per);
} else
if (entry == 't') {
printf("Please enter the length of two sides.\n");
scanf("%d %d", &num, &num1);
getchar();
rt(num, num1, area, per);
} else {
printf("Invalid input!");
}
display(entry, area, per);
return 0;
}
数据。
问题是每次用户按下&#34;拍照&#34;按钮,页面刷新和早期输入中填写的所有数据都会消失/删除。
我一直试图了解导致这种更新的原因,但无法弄清楚......
这是相关的HTML部分:
canvas
和JS:
console.log()
任何想法为什么点击 <div class="form-group">
<input minlength=8 type="password" class="form-control" name="pass" placeholder="Enter Password" required/>
</div>
<div class="form-group">
<div id="camera">
<div class="center clear">
<video id="video" width="320" height="240" autoplay></video>
<button id="snap">Take Picture</button>
<canvas id="canvas" width="320" height="240"></canvas>
</div>
</div>
刷新页面,我怎么能阻止它? THX
答案 0 :(得分:0)
如果您在<form>
内有var form = document.querySelector('form');
form.addEventListener('submit', function(event) {
event.preventDefault();
}, true);
,那么点击它会默认提交表单。为防止这种情况发生,您可以使用event.preventDefault
停止提交。
{{1}}
答案 1 :(得分:0)
如果其他人会遇到问题,我设法使用@Mike C的指导来解决这个问题...
我只需将其添加到button
:
<button id="snap" onclick="return false;">Take Picture</button>