js , цвет + <b> </b>

Discussion in 'PHP' started by IIAHbI4, 26 May 2008.

  1. IIAHbI4

    IIAHbI4 Banned

    Joined:
    24 Aug 2006
    Messages:
    276
    Likes Received:
    331
    Reputations:
    11
    Отвечу сразу на вопроссы:
    Да хаккир.
    Да крутой чтоле.
    С соседнего района.
    Попечене ненадо.
    Норкоман чтоле.

    По существу, вот есть код
    HTML:
    if(days != 0){out += days +" <b> Дней</b>"+((days!=1)?"":"")+", ";}
    		if(days != 0 || hours != 0){out += hours +"<b> часов</b>"+((hours!=1)?"":"")+", ";}
    		if(days != 0 || hours != 0 || mins != 0){out += mins +"<b> минут</b>" + ((mins!=1)?"":"")+", ";}
    		out += secs +" секунд";
    
    как мне выделить <b></b> жирным не само слово "Дней" а цифру которая перед этим словом ? И предать определённый цвет ... ну #336600 к примеру.


    ***
    Вобщето попробовал нопесать таймер обратного отсчета от нынешней даты, до грядущего дня, и вот нужно выделить, полный код ниже -->

    HTML:
    <SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
    <!-- //start
    dateFuture = new Date(2008,5,5,24,0,0);
    
    // Панеч (с) 2008.
    
    function GetCount(){
    
    	dateNow = new Date();									//скрипт берёт нынешнюю дату
    	amount = dateFuture.getTime() - dateNow.getTime();		//тут считаем милисекунды между датами
    	delete dateNow;
    
    	// тут уже прошло время
    	if(amount < 0){
    		document.getElementById('countbox').innerHTML="УРА!";
    	}
    	// date is still good
    	else{
    		days=0;hours=0;mins=0;secs=0;out="";
    
    		amount = Math.floor(amount/1000);//убиваем милисекунды
    
    		days=Math.floor(amount/86400);//дни
    		amount=amount%86400;
    
    		hours=Math.floor(amount/3600);//часы
    		amount=amount%3600;
    
    		mins=Math.floor(amount/60);//минуты
    		amount=amount%60;
    
    		secs=Math.floor(amount);//секунде
    
    		if(days != 0){out += days +" <b> Дней</b>"+((days!=1)?"":"")+", ";}
    		if(days != 0 || hours != 0){out += hours +"<b> часов</b>"+((hours!=1)?"":"")+", ";}
    		if(days != 0 || hours != 0 || mins != 0){out += mins +"<b> минут</b>" + ((mins!=1)?"":"")+", ";}
    		out += secs +" секунд";
    		document.getElementById('countbox').innerHTML=out;
    
    		setTimeout("GetCount()", 1000);
    	}
    }
    
    window.onload=function(){GetCount();}//call when everything has loaded
    //-->
    </script>
    
     
  2. FeraS

    FeraS Elder - Старейшина

    Joined:
    19 Jan 2007
    Messages:
    555
    Likes Received:
    420
    Reputations:
    76
    \"<strong>\" + … + \"</strong>\"
     
  3. IIAHbI4

    IIAHbI4 Banned

    Joined:
    24 Aug 2006
    Messages:
    276
    Likes Received:
    331
    Reputations:
    11
    блять про слэши забыл. Фер а что с цветом? такая тема прокатит?
    <span class="style1">\"<strong>\" + … + \"</strong>\" </span>
     
  4. IIAHbI4

    IIAHbI4 Banned

    Joined:
    24 Aug 2006
    Messages:
    276
    Likes Received:
    331
    Reputations:
    11
    Фер, не катит ... бльть, помогите хоть разгуглить, либо Ихю натравите на тему.
     
  5. FeraS

    FeraS Elder - Старейшина

    Joined:
    19 Jan 2007
    Messages:
    555
    Likes Received:
    420
    Reputations:
    76
    if(days != 0){out += \"<strong>\" + days \"</strong>\"
    нет, да?
     
  6. IIAHbI4

    IIAHbI4 Banned

    Joined:
    24 Aug 2006
    Messages:
    276
    Likes Received:
    331
    Reputations:
    11
    неа, хз... щас чёнить покурю из литературы.
     
  7. astrologer

    astrologer Elder - Старейшина

    Joined:
    30 Aug 2007
    Messages:
    837
    Likes Received:
    267
    Reputations:
    59
    Code:
    'строка'.bold();
    Code:
    amount %= 86400;
    Code:
    window.onload = GetCount;
    Code:
    
    
    Code:
    setTimeout(GetCount, 1000);
    etc.
     
  8. bul.666

    bul.666 булка

    Joined:
    6 Jun 2006
    Messages:
    719
    Likes Received:
    425
    Reputations:
    140
    Чета я не понил!
    Этож бонально:
    PHP:
    var stl1 "<span style='color: #FF0000'><b>"//Открытый тэг стиля
    var stl2 "</b></span>"//Закрытый
            
    if(days != 0){out +=stl1+days+stl2+" Дней"+((days!=1)?"":"")+", ";}
            if(
    days != || hours != 0){out += stl1+hours +stl2+" часов"+((hours!=1)?"":"")+", ";}
            if(
    days != || hours != || mins != 0){out += stl1+mins +stl2+" минут" + ((mins!=1)?"":"")+", ";}
            
    out += stl1+secs +stl2+" секунд";
    Проверил В Осле и Опере...
    -
    ХЗ Иожет я дурак
     
    1 person likes this.
  9. banned

    banned Banned

    Joined:
    20 Nov 2006
    Messages:
    3,324
    Likes Received:
    1,194
    Reputations:
    252
    bulka, Qele, Qele :D
    PHP:
    var stl1 "<span style='color: #F00;font-weight:bold;'>"//Открытый тэг стиля
    var stl2 "</span>"//Закрытый
     
    3 people like this.
  10. IIAHbI4

    IIAHbI4 Banned

    Joined:
    24 Aug 2006
    Messages:
    276
    Likes Received:
    331
    Reputations:
    11
    Буль ты не понял, чветным и жирным должны быть только цифры, тобишь Дни, минуты секунды ... так щас проверю. Ихес спасибо :)
     
    1 person likes this.
  11. astrologer

    astrologer Elder - Старейшина

    Joined:
    30 Aug 2007
    Messages:
    837
    Likes Received:
    267
    Reputations:
    59
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
    <style type="text/css">
    
    #countbox
    {
      font-family: "Lucida Grande", Calibri, Georgia, Verdana;
    }
    
    #countbox .unit
    {
      margin-left: 3px;
      font-size: 80%;
    }
    
    </style>
    
    <script type="text/javascript">
    
    var Countdown =
    {
      timer: null,
      init: function(id, until)
      {
        Countdown.node  = document.getElementById(id);
        Countdown.update(until);
        Countdown.timer = setInterval(function()
        {
          Countdown.update(until);
        }, 1000);
      },
    
      stop: function()
      {
        clearInterval(Countdown.timer);
        return true;
      },
      
      update: function(until)
      {
        var s = Countdown.process(new Date(), until);
        Countdown.node.innerHTML = s || Countdown.stop() && 'Всё :)';
      },
      
      difference: function(before, after)
      {
        if (after < before) return false;
    
        var
        days   = after.getDate()  - before.getDate(),
        months = after.getMonth() - before.getMonth(),
        years  = after.getYear()  - before.getYear(),
        hms    = (after / 1000 - before / 1000) % 86400,
        
        seconds = Math.floor(hms % 60),
        minutes = Math.floor(hms/60) % 60,
        hours   = Math.floor(hms/3600) % 60,
    
        date = new Date();
    
        if (days < 0)
        {
          date.setFullYear(before.getYear(), before.getMonth(), 32);
          days += 32 - date.getDate();
          months--;
        }
    
        if (months < 0)
        {
          months += 12;
          years--;
        }
    
        return {
          years:   years,
          months:  months,
          days:    days,
          
          hours:   hours,
          minutes: minutes,
          seconds: seconds
        };
      },
    
      process: function(before, after)
      {
        var diff = null, a = [], i = '';
        if(!(diff = Countdown.difference(before, after))) return false;
    
        for(i in diff)
        {
          if(!diff[i]) continue;
          a.push('<span class="num">'
                  + diff[i] +
                 '</span><span class="unit">'
                  + Countdown.lang[i][Countdown.lang.choose( diff[i] )] +
                 '</span>');
        }
    
        return a.join(' ');
      },
    
      lang:
      {
        years:   ['год', 'года', 'лет'],
        months:  ['месяц', 'месяца', 'месяцев'],
        days:    ['день', 'дня', 'дней'],
        hours:   ['час', 'часа', 'часов'],
        minutes: ['минута', 'минуты', 'минут'],
        seconds: ['секунда', 'секунды', 'секунд'],
        choose:  function(n)
        {
          var m = n % 100, i = 2;
          if(m < 5 || 20 < m)
          {
            if((m %= 10) === 1)
            {
              i = 0;
            }
            else if(1 < m && m < 5)
            {
              i = 1;
            }
          }
          return i; 
        }
      }
    };
    
    window.onload = function()
    {
      Countdown.init('countbox', new Date(2010, 7, 29, 0, 0, 30));
    };
    
    </script>
    </head>
    <body>
    
    <span id="countbox"></span>
    
    </body>
    </html>
     
    1 person likes this.
  12. IIAHbI4

    IIAHbI4 Banned

    Joined:
    24 Aug 2006
    Messages:
    276
    Likes Received:
    331
    Reputations:
    11
    ты ближе всех к истине, я ещё немного переделал, но твёрдая пятёрка, это точно!