zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    ()Python在数学建模中的简单应用
    ()Python3 列表,数组,矩阵的相互转换
    差商代微商的方法求解一阶常微分方程
    ()LaTex 论文排版(1): Win10 下 LaTex所需软件安装 (Tex live 2018 + Tex studio)
    渐进记法(O,Ω,Θ)
    定义类型别名(typedef,using)
    安装Java和Tomcat
    用PHP语言刷OJ题
    函数模板
    数组操作符
  • 原文地址:https://www.cnblogs.com/BlueFly/p/1380511.html
Copyright © 2011-2022 走看看