Extract values from database fields and change + picture lazy loading, jquery lazy loading

Source: Internet
Author: User

Requirements: Mobile phone to open the details of a page, because of the speed or other reasons, the response is too slow, because the picture of the big reason, want to advanced, the picture in the page running situation and then slowly load (jquer delay load) http://www.w3cways.com/1765.html ()

Difficulty: Because the picture of the page is added in the editor

: Picture and text stored in a field in a database

: Implement the idea: Read this field from the database, replace the SRC in the field with Lazyload and return to the page

The main point here is how to replace the values in the fields in the data that are taken from the database and then convert the data directly to the page.

First of all

Public ActionResult Index (int id)
{

var model=new bll (). Getmodel (ID)

Model=replace (model)

Return model;//now returns the following: the SRC attribute in the database is changed to * * * *,

}

Expansion class for public model replace (model extension model)//pass in an entity

{

Two steps, depending on the situation, need not be

StreamReader reader = new StreamReader (model. ContentText, Encoding.UTF8);//Change the contents of a database field into a string
String AAA = Reader. ReadToEnd ();//Read All strings

String Aaa=model. Replace ("A", "B")//a is itself a string, B is a string that needs to be replaced

For example, string a= "ABCD" would turn into string a= "BBCD"

String bbb=model.pc the contents of the paragraph. Rep;ace ("A", "B");

MODEL.PC segment content = BBB;

Model. Mobile content = AAA;

Return model

}

Another step to the pit:

The reason is that the single quotation mark is a character, "" is to enclose a string, so the above "into" "just fine."

Because the value of the page is dynamically transmitted

So directly

Operation effect, has turned Src into data-original

Model. ContentText = bbb + " ";//The convenience test that is added directly in the text

Extract values from database fields and change + picture lazy loading, jquery lazy loading

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.