


A JavaScript example code to remove blanks at the end of a string_javascript skills
May 16, 2016 pm 04:35 PM<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>每天一个JavaScript实例-去除字符串末尾的空白</title> <script> function white(){ var input = document.getElementById("inputid"); var lines = input.value.split("\n"); var resultString = ""; for (var i = 0; i < lines.length; i++){ var string = lines[i].trim(); resultString += string + "-"; } alert(resultString); } </script> </head> <body> <textarea id="inputid" placeholder="请输入多行字符串"></textarea> <a href="#" onClick="white()">clickMe</a> </body> </html>
Detect lower version browsers, backward compatible:
if(typeof String.trim == "undefined") String.prototype.trim = function(){ return this.replace(/(^\s*)|(\s*$)/g,""); } }

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to deal with blanks when playing PPT slides

Detailed explanation of the method of converting int type to string in PHP

How to determine whether a Golang string ends with a specified character

How to check if a string starts with a specific character in Golang?

How to repeat a string in python_python repeating string tutorial

How to solve the problem of Chinese garbled characters when converting hexadecimal to string in PHP

PHP string manipulation: a practical way to effectively remove spaces

PHP String Matching Tips: Avoid Ambiguous Included Expressions
