处理字符串中的换行,将textarea中的带有换行的字符串变为逗号分隔的写法

 1 _setMultipleInputValues: function (param) {
 2             //Maybe need to modify here for the new parameter 
 3             //add a method to set input values from textarea
 4             if (param.Name == "AddedParameter1") {
 5                 bindingElement = true;
 6                 var textareaValue = "";
 7                 textareaValue = $("#" + param.Name + "_textarea").val();
 8                 var c;
 9                 for (var i = 0; i < textareaValue.length; i++)
10                 {
11                     c = textareaValue.substr(i, 1);
12                     if (c == "\n")
13                     {
14                         textareaValue = textareaValue.replace("\n", ",");
15                     }
16                 }
17                 $("#" + param.Name + "_fore").val(textareaValue.substr(0, textareaValue.length - 1));
18             }
19             else {
20                 var showValue = "";
21                 var hiddenValue = "";
22                 $("." + param.Name + "_DropDown_CB").each(function () {
23                     if (this.checked && this.value !== "Select All") {
24                         showValue += $("[name='" + param.Name + "_DropDown_" + this.value + "_lable']").html() + ",";
25                         hiddenValue += this.value + ",";
26                     }
27                 });
28                 $("#" + param.Name + "_fore").val(showValue.substr(0, showValue.length - 1));
29                 $("#" + param.Name + "_hidden").val(hiddenValue.substr(0, hiddenValue.length - 1));
30             }
31         },
_setMultipleInputValues

直接上代码,下面截图做说明:

转载于:https://www.cnblogs.com/zzuIvy/p/JavaScript_textarea_string.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值