It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

how to automatic add picture to a list?

how to automatic add picture to a list?

Postby cyyjm on Fri Apr 22, 2011 2:15 am

i want to automatic add img for my list.if text in span is today. code like this.

Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
  <style type="text/css">
.li_title {            list-style-type:none;

                       font-size:12px;
                       line-height:24px;
                       
                       }
.date {float:right;margin-right:3px;}


  </style>
</HEAD>

<BODY>
  <DIV id=Conttab_p_switch1 style="POSITION: relative">
            <UL>
                     <LI class="li_title"><span class="date">2011-04-22</span><A title=meeting(4-22) href="#" target=_blank>meeting(4-22)</A></LI>
                     <LI class="li_title"><span class="date">2011-04-11</span><A title=meeting(4-11) href="#" target=_blank>meeting(4-11)</A></LI>
                     <LI class="li_title"><span class="date">2011-04-04</span><A title=meeting(4-04) href="#" target=_blank>meeting(4-04)</A></LI>
                                                         
             </UL>
      </DIV>
</BODY>
</HTML>
cyyjm
 
Posts: 1
Joined: Wed Apr 13, 2011 8:17 am

Re: how to automatic add picture to a list?

Postby rajmv on Sun Jul 17, 2011 4:59 pm

This code should work;

but for some reason my local machine (firefox/win7) reports me as being exactly 1 month in the past.
therefore, i can't guarantee the accuracy of the Date() object.
something i'll have to look into next time i use Date() myself.


Code: Select all
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
      <style type="text/css">
    .li_title {            list-style-type:none;

                           font-size:12px;
                           line-height:24px;
                           
                           }
    .date {float:right;margin-right:3px;}


      </style>
    <script type="text/javascript"><!--
   
      function doIt() {
         var dt = new Date();
         var date =
            dt.getFullYear()
            + '-' + ( dt.getMonth()<10 ? '0'+dt.getMonth() : dt.getMonth() )
            + '-' + ( dt.getDate()<10 ? '0' + dt.getDate() : dt.getDate() );

         var ul = document.getElementById('myUL');
         for (var i = 0; i<ul.children.length; i++) {
            var li = ul.children[i];
            var span = li.children[0];
            if (span.innerHTML==date) {
               var html = '<img src="/path/to/img.jpg"/>';
               li.innerHTML = html + li.innerHTML;
            }
         }
         
      }
   
   --></script>
    </HEAD>

    <BODY onload="doIt()">
      <DIV id="Conttab_p_switch1" style="POSITION: relative">
                <UL id="myUL">
                         <LI class="li_title"><span class="date">2011-04-22</span><A title=meeting(4-22) href="#" target=_blank>meeting(4-22)</A></LI>
                         <LI class="li_title"><span class="date">2011-04-11</span><A title=meeting(4-11) href="#" target=_blank>meeting(4-11)</A></LI>
                         <LI class="li_title"><span class="date">2011-04-04</span><A title=meeting(4-04) href="#" target=_blank>meeting(4-04)</A></LI>
                                                             
                 </UL>
          </DIV>
    </BODY>
    </HTML>
rajmv
100+ Club
 
Posts: 103
Joined: Thu Jul 14, 2011 7:22 am


Who is online

Users browsing this forum: No registered users and 4 guests