Jquery mouse dynamic add text box auto update sort

Source: Internet
Author: User

Jquery automatically updates the sorting when the text box is dynamically added when the mouse clicks.

Start

Before update: only numbers are displayed in the sorting column.

When you place the cursor over a number, click it to change to a text box. Enter the number and move the mouse away. Automatic update.

Paste the Code:

$ (Document). ready (function (){
// Modify the topic id
$ (". BY"). click (function (){
Var r =/^ [0-9] * [1-9] [0-9] * $ // judge the regular expression of a positive integer.
Var old = $ (this). text ();
Var o = $ (this );
O.html ("<input class = \" OnBY \ "type = \" text \ "onMouseOver = \" this. select (); \ "value = \" "+ old +" \ "/> ");
$ (". OnBY"). blur (function (){
Var number = $ (". OnBY"). val (); // obtain the value in the text box.
Var columnid = o. attr ("DbID"); // obtain the ID number of the value column of the DbID attribute.
If (! R. test (number ))
{
Alert ("digit format error ");
$ (This). select ()
Return false;
}
If (number. length = 0) // determines whether a value exists in the text box.
{
Alert ("cannot be blank ");
$ (This). select ()
Return false;
}
Else // Jquery asynchronously updates the order number.
{
$. Ajax ({
Type: "GET ",
Url: "../AjaxAsyn/UpdateSortNo. aspx ",
Data: "ID =" + o. attr ("DbID") + "& BY =" + $ (". onBY "). val () + "& date =" + new Date (). getTime () + "& Type = 1", // Add a time parameter to indicate that the requested page is different. type indicates whether to change the order of the document or to the product, or a column.
BeforeSend: function (XMLHttpRequest) // The image waiting for updating is displayed.
{
$ ("# ShowResult" + columnid). show ();
},
Success: function (msg) // update successful
{
O.html ($ (". OnBY"). val ());
$ ("# ShowResult" + columnid). hide ();
// O.html (old );
}
});
}
});
});

Aspx page code:
<Div class = "col7">
<Span class = "BY" DbID = '<% # Eval ("id") %>' title = "click to modify"> <% # Eval ("SortNo ") %> </span>
</Div>

Background code for updating sorting:

ColumnId = Web. CommFun. UrlParameters. IntParameters (this, "ID ");
SortNo = Web. CommFun. UrlParameters. IntParameters (this, "");
DateTime = Web. CommFun. UrlParameters. StringParameters (this, "date ");
TypeNo = Web. CommFun. UrlParameters. IntParameters (this, "Type"); // TypeNo 1 modify topic number 2 modify Level 2 topic number 3 news article 4 product order
UpdateSorts ();
}
Private void UpdateSorts ()
{
Switch (TypeNo)
{
Case 1:
{
DAL. ColumnDAL dal = new DAL. ColumnDAL ();
If (dal. UpdateSortNo (columnId, SortNo)> 0)
{
Response. Write ("updated and sorted ");
Response. End ();
}
Else
{
Response. Write ("update failed! ");
Response. End ();
}
Break;
}
Case 2 :...

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.