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 :...