简体   繁体   English

使用javascript提交表单时将换行符添加到textarea字段

[英]Add line breaks to textarea field when submitting form with javascript

   <form onsubmit="location.href='https://www.example.com/test/?message=' + document.getElementById('message').value; return false;">
    <textarea id="message" name="message" placeholder="Message" rows="5" cols="50">
    </textarea>

    <input type="submit" value="Send" />
    </form>

If I make three lines of text in the textarea: 如果我在文本区域中输入三行文字:

AAA
BBB 
CCC

..it will return the url like this: ..它将返回如下网址:

https://www.example.com/test/?message=AAABBBCCC

I want to add linebreaks to the string in the url, so I can separate the values. 我想将换行符添加到url中的字符串,以便可以将值分开。

Why not split by new line char? 为什么不按换行符拆分? Or replace new line char with special char and parse on the server/frontend? 还是用特殊字符替换新的行字符并在服务器/前端进行解析?

Splitting text in textarea by new lines (including empty lines) into javascript array 用新行(包括空行)将textarea中的文本拆分为javascript数组

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM