今天遇到了一個(gè)問題,用戶在在前端的input里面輸入id的時(shí)候蹬挺,多寫了個(gè)空格,數(shù)據(jù)庫(kù)里面就找不到id了,所以無法獲取輸入的id所綁定的標(biāo)簽位置在哪里闰非,現(xiàn)在需要在前端做一個(gè)處理剩盒,input框輸入的數(shù)值里面,會(huì)自動(dòng)消除空格台夺。
代碼示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" >
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="modal-body form">
<div class="form-group">
<label class="col-sm-2 control-label" >資產(chǎn)編號(hào)<span class="required"> * </span></label>
<div class="col-sm-6">
<input type="text" class="form-control" id="assetId" onkeyup="this.value=this.value.replace(/[, ]/g,'')"></input>
</div>
</div>
</div>
</body>
</html>
這段代碼的作用:
onkeyup="this.value=this.value.replace(/[, ]/g,'')"
1:在input框里面輸入編號(hào)的過程中径玖,出現(xiàn)空格,自動(dòng)消除
2:input首尾出現(xiàn)空格颤介,自動(dòng)消除
3:復(fù)制粘貼的文本里面出現(xiàn)空格梳星,自動(dòng)消除
原文作者:祈澈姑娘 技術(shù)博客:http://www.reibang.com/u/05f416aefbe1
90后前端妹子赞赖,愛編程,愛運(yùn)營(yíng)冤灾,文藝與代碼齊飛前域,魅力與智慧共存的程序媛一枚。
堅(jiān)持總結(jié)工作中遇到的技術(shù)問題韵吨,堅(jiān)持記錄工作中所所思所見