首页 > 解决方案 > 如何将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>'''

我怎么能做这样的事情?

所有这些事情都需要在提交之前发生

标签: pythonhtmlbottle

解决方案


'''<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)

推荐阅读