jquery的val() 的疑惑 ...

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

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

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


<script src="../js/jquery.pack.js" type="text/javascript"></script>
<script src="../js/jquery-1.2.6-vsdoc.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
$(
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>
posted @ 2009-01-23 17:25  BlueFly  阅读(3085)  评论(4编辑  收藏  举报