表单提交是必须要的,否则验证不了(注:这个是 HTML 的,剩下的我不知道!)
js(表单提交):
function validateForm() {
// 获取输入字段的值
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
// 验证用户名和密码是否为空
if (username === "" || password === "") {
document.getElementById("error-message").textContent = "请输入用户名和密码";
return false; // 阻止表单默认提交方式
}
// 可以根据需要添加其他验证规则
return true; // 允许表单提交
}
py(表单验证)
from bs4 import BeautifulSoup
def validate_html(html_code):
try:
soup = BeautifulSoup(html_code, 'html.parser')
# 如果解析成功,则HTML代码是有效的
return True
except Exception as e:
print('HTML validation error:', e)
return False
# 要验证的HTML代码
html_code = '<html><head><title>Example</title></head><body><h1>Hello, world!</h1></body></html>'
# 验证HTML代码
is_valid = validate_html(html_code)
print('Is HTML valid?', is_valid)
这样就完成了!
最后注意一段js代码:
action="ciee_Login.py"
这样就完成了!