简体   繁体   中英

Blinking text in a textarea field

I have a text area in a 404 page on my website that is a monologue from the webserver to the user. This text uses a | character to represent the 'cursor' position in the monologue. Unfortunately, this character does not blink. After googling around and finding http://en.wikipedia.org/wiki/Blink_element#Implementation , I tried adding it to the page, but when I put the tags around the | , it shows as a literal instead of being interpreted.

The function for displaying the text is

      function type_text()
  {
    contents='';
    row=Math.max(0,index-7);
    while(row < index)
    {
      contents += tl[row++] + '\r\n';
    }
    document.forms[0].elements[0].value = contents + tl[index].substring(0,text_pos) + "<blink>|</blink>";
    if(text_pos++==str_length)
    {
      text_pos=0;
      index++;
      if(index!=tl.length)
      {
        str_length=tl[index].length;
        setTimeout("type_text()",1500);
      }
    } else
      setTimeout("type_text()",speed);
  }

This is of course in Javascript.

I used this to script the <blink> tags:

function blink() 
{
    var blinks = document.getElementsByTagName('blink');
    for (var i = blinks.length - 1; i >= 0; i--) 
    {
        var s = blinks[i];
        s.style.visibility = (s.style.visibility === 'visible') ? 'hidden' : 'visible';
    }
window.setTimeout(blink, 500);
 }

  if (document.addEventListener) document.addEventListener("DOMContentLoaded", blink, false);
  else if (window.addEventListener) window.addEventListener("load", blink, false);
  else if (window.attachEvent) window.attachEvent("onload", blink);
  else window.onload = blink;

If it helps at all, my page can be found here: http://paradoxwow.com/404.shtml I have a 'Test' message blinking in the bottom left, but the | won't blink.

Thanks ahead.

A textarea cannot contain HTML, so you're out of luck there. Since you aren't really using the textarea for input, why use a textarea at all? Use a div instead, and modify your code appropriately.

The content of textarea is just text, so all markup is ignored (taken as text data). So you could make the entire content blink, but not just part of it.

It is illogical and pointless to use textarea when you are not expecting user input. You can use a pre element, inside which markup is recognized, though just a limited set of tags is allowed in principle, but you can use blink or styled span there. Alternatively, use a p or div with suitable styling, such as white-space: pre .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM