Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 取消隐藏已从文本框中删除的隐藏单词_Javascript_Jquery_Html - Fatal编程技术网

Javascript 取消隐藏已从文本框中删除的隐藏单词

Javascript 取消隐藏已从文本框中删除的隐藏单词,javascript,jquery,html,Javascript,Jquery,Html,我想允许用户从词库中选择给定的单词,并将它们放入文本框中,在文本框中它们将从词库中删除(隐藏)。如果用户犯了一个错误并想要回这个单词,他们可以从文本框中删除它,然后将它放回单词库 如何做到这一点?(请原谅可怕的ms绘画图像) HTML: 编辑: var array = []; var i = 0; $.each($('#textBox').val().split(/\s+/), function(index, word) { array.push(word); log("AR

我想允许用户从词库中选择给定的单词,并将它们放入文本框中,在文本框中它们将从词库中删除(
隐藏
)。如果用户犯了一个错误并想要回这个单词,他们可以从文本框中删除它,然后将它放回单词库

如何做到这一点?(请原谅可怕的ms绘画图像)

HTML:


编辑:

var array = [];
var i = 0;
$.each($('#textBox').val().split(/\s+/), function(index, word) {
    array.push(word);
    log("ARRAY: " + array[i] + array.length);
    i++;
    console.log( index + ": " + word);

    for (obj in words) {
        for (key in words[obj]) {

         //if word doesn't exist in text box, and doesn't exist in word bank, add it
        if (!isInArray(key, array) && is in wordbank...) {
            key.show(); //pseudo code
        }
    }
    }

});

function isInArray(value, array) {
  return array.indexOf(value) > -1;
}

只要用文本框中的每个单词遍历单词数组,将每个缺少的条目附加到$(“.wordBank_words”)。@Lakshmi但是你怎么知道缺少哪个单词呢?如果该单词已被删除,则该单词不再存在于文本框中的单词数组中。按相反的方式执行。。检查您单词列表中每个单词的文本框数组,查看是否有任何遗漏条目,将其附加到$(“.wordBank_words”)@Lakshmi,但我只想将该单词放回单词库,前提是用户之前已选择该单词(也就是说,它以前已被隐藏)。如果我只是在文本框数组中循环并将其与我的单词列表进行比较,它只会添加回单词列表中文本框中缺少的单词。请在您的银行中使用,而不是
  • ,这样您就可以隐藏/取消隐藏单词,而无需将其追加回列表中。所以单词库中的每个单词都是div。
    $(document).ready(function() {
        playerResponse();
    
        $(".bank-word").click(function (event) {
    
            //append each newly selected word to $('#textBox').val() 
            $('#textBox').val($('#textBox').val() + " " + $(this).attr('word'));
    
            //hide word from word bank
             $(this).hide();
    
             /*THIS IS THE PORTION I AM HAVING TROUBLE WITH*/
            //Get all words from text box
            //if word is hidden and does not exist in text box... add it back
        $.each($('#textBox').val().split(/\s+/), function(index, word) {
            console.log( index + ": " + word);
    
            $('li.bank-word').find(':hidden').each(function(index) {
                log("index : " + index + ", " + $(this).text());
                $(this).show(); //reveal word in word bank again after we find that it is hidden AND has been deleted from text box
            });     
        });
    
        });
    
    });
    
    var words = {
        "task1" :
        {
            'Ni'    : 'you',
            'Wo'    : 'I',
            'Hao'   : 'good',
            'Shi'   : 'am'  
        }
    }
    
    function bank() {
        $(".wordBank_Words").empty();
        for (obj in words) {
            for (key in words[obj]) {
                 $(".wordBank_Words").append("<li class='bank-word' word='" + key + "' ><b>" + key + "</b>: " + words[obj][key] + "</li>");
            }
        }
    }
    
    function submitMe() {
    //will eventually verify input from textbox
        var value = document.getElementById('test').value;
        alert(value);
    }
    
    var array = [];
    var i = 0;
    $.each($('#textBox').val().split(/\s+/), function(index, word) {
        array.push(word);
        log("ARRAY: " + array[i] + array.length);
        i++;
        console.log( index + ": " + word);
    
        for (obj in words) {
            for (key in words[obj]) {
    
             //if word doesn't exist in text box, and doesn't exist in word bank, add it
            if (!isInArray(key, array) && is in wordbank...) {
                key.show(); //pseudo code
            }
        }
        }
    
    });
    
    function isInArray(value, array) {
      return array.indexOf(value) > -1;
    }