python - 如何将python if语句添加到html中的onchange事件
问题描述
你好
我的带有 html 代码的示例字符串:
x = '''<input type="text" name="firstname">
<input type="text" name="firstname1">
<input type="text" name="firstname2">
<input type="text" name="txt" onchange="myFunction()">
<input type="submit" value="Submit">
<script>
function myFunction() {
''' --->python code--->if request.forms.get('txt'):
return x= "ok"
'''
}
</script>'''
我怎么能做这样的事情?
所有这些事情都需要在提交之前发生
解决方案
'''<input type="text" name="firstname">
<input type="text" name="firstname1">
<input type="text" name="firstname2">
<input type="text" name="txt" onchange="myFunction()">
<input type="submit" value="Submit">
<script>
function myFunction() {
{}
}
</script>'''.format(THE PYTHON CODE THAT EVALUATE TO TEXT)
推荐阅读
- python - 遍历 Python 中的字符串列表
- java - JInternalFrame - 非法组件位置
- python - 并发任务确定性地生成伪随机数
- html - 如何将导航元素定位在标题元素下?
- angular - 将嵌套对象从角度绑定到 webapi
- python - 如何在 tensorflow 中训练卷积滤波器
- javascript - 为什么我会得到 Promise {
在 Promise.all 中使用 fetch 时? - c - 指针时无法使用箭头符号访问结构数据
- mysql - 派生表不存在 - mySQL 错误 1146 (42S02)
- c - 在 C 中使用 GnuTLS 生成 RSA 密钥对