Python HTML文本框没有';不要在空格后读取数据
以下是示例代码:Python HTML文本框没有';不要在空格后读取数据,python,html,Python,Html,以下是示例代码: <form action= 'file.php'> <br/><br/> Enter the numbers selected separated by a comma <input type = "text" style="white-space:nowrap;" name= "number"> <br/> <input type = "submit"> </form> 输入所
<form action= 'file.php'>
<br/><br/>
Enter the numbers selected separated by a comma <input type = "text"
style="white-space:nowrap;" name= "number"> <br/>
<input type = "submit">
</form>
输入所选数字,以逗号分隔
以以下格式输入输入时:
2,3,4
我可以正确地解析它。但是,如果用户输入为:
2,3,4
(有空格)
后端python程序只读取到第一个空格。
HTML中是否有忽略空白的选项
Python使用以下命令读取:
var=sys.argv
如果可以,请在提交之前使用javascript“清除”用户输入中的空白
<form action= 'file.php' onsubmit="cleanInput()">
<br/><br/>
Enter the numbers selected separated by a comma <input type = "text"
style="white-space:nowrap;" name= "number"> <br/>
<input type = "submit">
</form>
<script>
function cleanInput() {
var inp = document.getElementsByName("number")[0];
inp.value = inp.value.replace(/\s/g, ""); // Clean whitespace
}
</script>
输入所选数字,以逗号分隔
函数cleanInput(){
var inp=document.getElementsByName(“编号”)[0];
inp.value=inp.value.replace(//\s/g,“”;//清除空白
}
使用
sys.argv
(我想,您可以使用popen
或类似的工具直接调用/传递python脚本的参数)以外的其他工具读取输入可能会更好,但是js可以提供一个快速解决方案。如果您向我们展示您的python代码,可能会有所帮助