Hli Archives: Tej zaum 2011

Tsis tau ntxiv jQuery–Resize ib qho piv txwv ua tus duab

Kuv pub ib cov qhov Web site ntawm ib tug neeg laus vendor thiab yuav ua tau ib qho teeb meem loj, me duab.  Cov dluab yuav tsum muaj 60×50 tab sis vim khib, tus thawj vendor yuam lawv ua 42×42, li ntawd, lawv nrhiav squashed:

 

Cov duab zoo

Teeb duab

Ntawm no yog cov markup (dog dig yooj yim zog):

<table hoob = 'ncua-outlook'>
  <thead>
    <tr>
      <th  dav ='100′>3 Tuesday</th>
    </tr>
  </thead>

  <tbody>
    <cov chav kawm tr = 'huab cua'>
      <Td dav ='100′>
        <ul>
          <lis hoob = 'high'>Siab: 72&deg;F</lis>
          <lis hoob = 'low'>Qes: 44&deg;F</lis>
          <lis hoob = 'mob'>Tshav ntuj
            <img src =’
http://deskwx.weatherbug.com/images/Forecast/icons/localized/60×50/en/Trans/cond007.png’ dav ='42’ qhov siab ='42’ xwm =” />
          </lis>
        </ul>
      </Td>
    </tr>

  </tbody>

</cov lus>

Koj mam li nco tias txawm ho lub kev ua kom cov duab xwb qhia qhov kom zoo dimension (60×50) tus thawj vendor yuam nws hauv 42×42.  Ua li cas?  Vwm.

Xijpeem, Kuv xav tau txoj kev sai thiab yooj yim tov rau no qhov teeb meem thiab kuv muab rau jQuery.  Qhov ua kom yuam kev los nrhiav tau txhua yam txog qhov tsim nyog tau <img> cim npe.  Kuv tsis xav muck cov cim kev lwm img npe (cov uas muaj ntau ntau).  JQuery no me ntsis puas tau qhov ua kom yuam kev:

<Script yam = "ntawv nyeem/javascript" src ="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></tsab ntawv>

<Script yam = "ntawv nyeem/javascript">
     $(daim ntawv).npaj txhij(muaj nuj nqi () {

         $(' li.condition > img').txhua(muaj nuj nqi (Performance Index, yam khoom)
           
{
             $(yam khoom).CSS("dav", "60"); 
             $(yam khoom).CSS(qhov "siab", "50");
            });
     }); // nyob rau daim ntawv load
</tsab ntawv>

Chaws ntawd me ntsis pom qhov sau los ua <lis> cim npe cov hoob kawm uas nws yog "mob" thiab <img> cov me nyuam.  Nws mam li iterates los ntawm tag nrho cov neeg ntawd.  Ua haujlwm zoo li ib lub nplhaib.

Kuv yuav zaum khiav nws, tab sis kuv yeej tsis muaj ib hom txiv leej tub unix tias solved π mus 18 xaus-npawb tsab precision sed thiab cov awk thiab kuv tsis ntawd seb yog jQuery guy tog twg los Luag nyav.

</kawg>

Subscribe rau kuv blog.

Raws li kuv nyob Twitter tom http://www.twitter.com/pagalvin

Parsing XML nrog LINQ

Ntawm no yog tus ceev kev piv txwv uas siv cov LINQ los parse ib co  XML thiab mus rau hauv lub qab zib, qab mib attributes therein.

Nov yog lub XML kuv xav parse:

<?xml version = "1.0 Tub ntxhais" encoding = "utf-8" ?>
<DeafultConfigurationSets>
  <PageLayouts>

    <PageLayout npe = "xyzzy">
      <Tabs>
        <Tab TabOrder = "1" TabLabel = "x" SharePointContentType = "ib" AdditionalConstraints = "ac1" />
        <Tab TabOrder = "2" TabLabel = "y" SharePointContentType = "b" AdditionalConstraints = "ac2" />
      </Tabs>
    </PageLayout>

    <PageLayout npe = "xyzzy2">
      <Tabs>
        <Tab TabOrder = "100" TabLabel = "x" SharePointContentType = "ib" AdditionalConstraints = "ac1" />
        <Tab TabOrder = "101" TabLabel = "y" SharePointContentType = "b" AdditionalConstraints = "ac2" />
        <Tab TabOrder = "103" TabLabel = "z" SharePointContentType = "c" AdditionalConstraints = "ac3" />
      </Tabs>
    </PageLayout>

  </PageLayouts>
</DeafultConfigurationSets>

Kuv xav tau ib co tabs tom runtime tsim los ntawm parsing cov saum no.  Kuv tabs vam li ib phab layout.  Yog kuv tus nplooj layout lub npe hu ua "xyzzy2" ces kuv xav tau tabs 100, 101 thiab 103 (tus tabs hauv <PageLayout npe = "xyzzy2">).

Ntawm no yog cov LINQ uas yog nws:

Var allTabs =
              ntawm p hauv
                  XElement.Parse(theXmlToParse).
                 
Ntsiab("PageLayouts").
                  Ntsiab("PageLayout")
              nyob qhov twg (p.Attribute("lub npe").Value.Equals("xyzzy2"))
              ntawm m hauv p.Elements("Tabs").Ntsiab("Tab")
              xaiv m;

          Results.Text = hlua.Npliag;

          foreach (Var aTab nyob allTabs)
          {
              Results.Text =
                  "Kev txiav txim tab: " + aTab.Attribute("TabOrder").Tus nqi + " |" +
                  "Tab lo cim: " + aTab.Attribute("TabLabel").Tus nqi + " | " +
                  "SharePointContentType: " + aTab.Attribute("SharePointContentType").Tus nqi + " | " +
                  "AdditionalConstraints: " + aTab.Attribute("AdditionalConstraints").Tus nqi + "r";
          }

Nyob rau saum no, kuj sib txawv rau thiab "theXmlToParse" yog ib txoj hlua kuj sib txawv thiab, tab sis, koj yuav tau siv cov load() txoj kev ntawm ib tug kwj yog hais tias koj nyiam.

"Tau" yog ib daim ntawv lo ntawm cov qhov web daim ntawv thiab thaum cov code no executes, nws zoo li no:

SNAGHTML11cd2e7c

Kuv tsis tau ua haujlwm tawm yuav txheeb soj ntsuam tsis tau li cas, li ntawd, kuv ces cia ntawd rau tus tom ntej blog ncej.

</kawg>

Subscribe rau kuv blog.

Raws li kuv nyob Twitter tom http://www.twitter.com/pagalvin