English 中文(简体)
利用Javascript 掩盖言词
原标题:Using Javascript to hide words in a string
  • 时间:2009-09-01 19:01:27
  •  标签:

我用贾瓦特语来掩盖言词。 例如,隐藏着第一和第六字或东西。 我的猜测是,从PHP的背景来看,它会这样做。

  1. You have a DIV with a sentence in it.
  2. You get the value of the DIV (the text sentence).
  3. You split the text by spaces " " to get each word.
  4. You then surround each word with a SPAN and id or class.
  5. You place all the words with the spans around them back into the DIV.
  6. Then from user interaction (or timeout events) you can hide each SPAN[text]SPAN as needed.

这是否是处理这一问题的适当途径?

最佳回答

我是这样说的。 事实上,我确实做了:

<div>
The dog jumps over the log.
</div>
<script type="text/javascript">
function boxWords(textNode) {
    var frag = document.createDocumentFragment(),
        // trim leading and trailing whitespace to avoid empty elements
        words = textNode.nodeValue.replace(/(^s+)|(s+$)/g,   ).split(   );

    for(var i = 0, len = words.length; i < len; ++i) {
        frag.appendChild(document.createElement( span ).appendChild(
            document.createTextNode(words[i])).parentNode);
        frag.appendChild(document.createTextNode(   ));
    }

    textNode.parentNode.replaceChild(frag, textNode);
}

var div = document.getElementsByTagName( div )[0];
boxWords(div.firstChild);

// underline the 4th word
div.getElementsByTagName( span )[3].style.textDecoration =  underline ;
</script>
问题回答

我不相信第4级和6级步骤有什么目的? 如果你用第3步的精通话的话,你就可以保留这一阵列,在你需要做事情时,总是能够使用适当的字眼。

你在想做些事情的时候,仍然必须从中看到什么。 您基本上以不同形式为贵族主制造同样的问题,

我认为,总的想法是,......

iv的内html,按“,然后按每一字的数值,将其分成一个独一无二的圆环...... 您可以保持空间中相对的字体,不为人知,或者你可以通过使内人“......”而使句子倒塌。

function divclick(id)
{
    //document.getElementById(id).style.visibility="hidden";
        // OR 
    //document.getElementById(id).innerHTML = "";
}

getting四分五裂,重新编成自己的一字,......这必然是大片交易...... 你们唯一必须考虑的是,什么事件造成言辞消失或出现。





相关问题
热门标签