zoukankan      html  css  js  c++  java
  • textarea存起来的数据把空格也存起来

    textarea的属性wrap="hard"可以把换行的内容也存起来。
    <html>
    
    	<head>
    		<title>这是一个小测试</title>
    		<meta name="" content="" charset="utf-8" />
    		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    	</head>
    
    	<body>
    		<div class="">
    			<textarea name="" rows="10" cols="100" wrap="hard"></textarea>
    		</div>
    		<div class="">
    			<button class="btn1">点击提交</button>
    			<button class="btn2">点击获取</button>
    		</div>
    		<div class="content">
    
    		</div>
    	</body>
    	<script src="jq.js"></script>
    	<script type="text/javascript">
    		var getFormatCode = function(strValue) {
    			return strValue.replace(/
    /g, '<br/>').replace(/
    /g, '<br/>').replace(/s*/g, '');
    		}//这个js一定不能丢
    		$('.btn1').on('click', function() {
    			$.ajax({
    				type: "get",
    				url: "http://*/login?text=" + getFormatCode($('textarea').val()),
    				async: true,
    				success: function(res) {
    
    					if(res.code == 0) {
    						alert('提交成功')
    					}
    				}
    			});
    		})
    
    		$('.btn2').on('click', function() {
    			$.ajax({
    				type: "get",
    				url: "http://*/text",
    				async: true,
    				success: function(res) {
    					if(res.code == 0) {
    						$('.content').html(res.msg)
    					} else {
    						alert('fail')
    					}
    				}
    			});
    		})
    	</script>
    
    </html>
    

      

    这样就把多行文本的回车也存了起来

  • 相关阅读:
    sed command
    【Python3】作用域(局部变量、全局变量)
    【Python3】函数与参数
    【Python3】编程范式
    【Python3】字符解码与编码
    【Python3】文件操作
    【Python3】集合
    【Python3】目录
    【Python3】字典
    【Python3】字符串操作
  • 原文地址:https://www.cnblogs.com/yiyi17/p/8710300.html
Copyright © 2011-2022 走看看