我想完成的功能是将多行文本框中的回车换行符(\r\n) 替换成逗号(,)。

使用var s = document.all('TextBoxData').value获取其值时,程序工作正常,但使用$("#TextBoxData").val()获取其值时,程序工作不正常。

百思不得其解,郁闷中...


$(function() {
$(
"a").focus(function() { this.blur(); }); 
$(
"#btnCancel").click(function() { window.close(); }); 
$(
"#btnOK").click(function() 

var values = $.trim($("#TextBoxData").val()); 
if (values.length == 0

window.alert(
"注意:您没有输入任何项。若放弃输入请按“取消”。"); 
return false

else 

var s = document.all('TextBoxData').value; //若使用 var s = values; 则无法完成\r\n --> “,”的替换!$("#TextBoxData").val()是如何获取 textarea 中的value?
= s.replace(/\r\n/g, ","); 
window.returnValue 
= s; 
window.close(); 

return false
}); 
});
</script>
<form id="form1" runat="server">
     
<div style="width: 99%">
     
<div style="padding: 10px; text-align: center">
<asp:textbox id="TextBoxData" runat="server" height="300px" width="100%" textmode="MultiLine"> </asp:textbox></div>
     
<div style="padding: 20px; text-align: center"> <asp:button id="btnOK" runat="server" text="确定" width="60px">   <asp:button id="btnCancel" runat="server" text="取消" width="60px"> </asp:button></asp:button></div>
     
<div> 注:请在文本框中输入若干行单列的值。</div>
     
</div>
</form>

相关文章:

  • 2022-12-23
  • 2021-05-25
  • 2022-01-15
  • 2022-01-02
  • 2021-07-18
  • 2022-12-23
  • 2021-11-22
猜你喜欢
  • 2021-05-06
  • 2021-09-09
  • 2022-01-06
  • 2021-05-20
  • 2021-08-29
  • 2021-11-09
  • 2022-12-23
相关资源
相似解决方案