Question about jquery's Val...

Source: Internet
Author: User

The function I want to complete is to replace the carriage return linefeed (\ r \ n) in the multi-line text box with a comma (,).

UseVaRS=Document. All ('Textboxdata'). Value to obtain its value,ProgramWork properly, but use$ ("# Textboxdata"). Val ()The program does not work properly when obtaining the value.

Puzzling, depressing...

HTML code
< 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 ( " Note: You have not entered any items. If you discard the input, click "cancel ". " );
Return   False ;
}
Else  
{
VaR S = Document. All ( ' Textboxdata ' ). Value; // If var S = values is used, \ r \ n --> "," cannot be replaced! $ ("# Textboxdata"). Val () is how to obtain the value in textarea?
S = 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 = "OK" Width = "60px" > < ASP: button ID = "Btncancel" Runat = "Server" Text = "Cancel" Width = "60px" >   </ ASP: button > </ ASP: button > </ Div >
< Div > Note: Enter the values of multiple rows in a single column in the text box. </ Div >
</ Div >
</ Form>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.