處理字符串中的換行,將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

直接上代碼,下面截圖做說明:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM