簡體   English   中英

HTML文本框在空格后不讀取數據

[英]HTML text-box does't read data after spaces

這是示例代碼:

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

sys.argv以外的其他方式讀取輸入可能會更好(我猜想,您可以直接使用popen或類似方法調用/傳遞python腳本的參數),但是js可以提供快速解決方案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM