• 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=" 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>
  • 相关阅读:
    微软RPC技术学习小结
    [COM Interop学习小结]实现一个C#调用C++的示例
    [一个小问题]Mainfest配置文件的version问题小结
    【小结】IIS7下的Http Native Module开发
    Active Sync与IIS7 Classic&Integrated模式,Exchange 2007&2010的关系
    是否能在构造函数,析构函数中抛出异常?
    Trouble Shooting的一些感想(实时补充)
    python中 try、except、finally 的执行顺序
    Hessian怎样实现远程调用
    mysql的三种驱动类型
  • 原文地址:https://www.cnblogs.com/BlueFly/p/1380511.html
Copyright © 2020-2023  润新知