English 中文(简体)
原文不明确
原标题:Script says Undefined
  • 时间:2011-11-22 01:47:20
  •  标签:
  • javascript

我有这一文字,使用户能够输入案文,并将翻译成其他内容。 只有在该词只有一封信时才行。 当有1多封信时,它说不明确。

页: 1

function copyit(theField) {
    var tempval = eval("document." + theField)
    tempval.focus()
    tempval.select()
    therange = tempval.createTextRange()
    therange.execCommand("Copy")
}

function results() {
    var behavior = "form";
    var text = document.csrAlpha.csrresult2.value;
    var ff22 = text.toLowerCase();
    var Words = new Array;
    Words["b"] = "Dadada";
    Words["bob"] = "Robert";
    Words["flower"] = "Banana";
    Words["brad"] = "Chair";
    var trans = "";
    var regExp = /[!@#$%^&*(),=";:/]/;
    var stringCheck = regExp.exec(ff22);
    if (!stringCheck) {
        if (ff22.length > 0) {
            for (var i = 0; i < ff22.length; i++) {
                var thisChar = ff22.charAt(i);
                trans += Words[thisChar] + " ";
            }
        } else {
            trans += "Please write something.";
        }
    } else {
        trans += "You entered invalid characters. Remove them and try again.";
    }
    document.csrAlpha.csrresult.value = trans;
}

And the HTML:

<table>
  <tr>
    <td align="center" class="cleanuphtml-1">
      <form name="csrAlpha">
        Please insert your text below:<br />
        <input type="text" class="tb3" name="csrresult2" size="70" maxlength="120" autocomplete="off" onkeydown="results()" onkeyup="results()" onkeypress="return handleEnter(this, event);" />
        <input type="reset" value="Reset" onclick="csrAlpha.csrresult2.focus();" />

        <p>
          <textarea name="csrresult" class="tb7" cols="71" rows="10" value=""></textarea>
        </p>
      </form>
    </td>
  </tr>
</table>
问题回答

如果这个词不出现在你的阵列中,那么你就会没有定义。 如果你是“Bo”,那么你会因为“Bo”不在你的阵列而没有定义。

你们正在用主要活动打字。 如果用户试图打造Bob,情况就是如此。

b) 阵容,无问题

船只——船只没有如此界定的阵列

bob -- javascript bombs at bo so you don t get this far.

我不知道你从哪里 co过来,也不知道你为什么甚至考虑以这种方式这样做。

这是一项更好的执行。 接下来,请在依靠他人之前进行一些研究。

页: 1

        <table>
          <tr>
            <td align="center" class="cleanuphtml-1">
              <form name="csrAlpha">
                Please insert your text below:<br />
                <input type="text" class="tb3" name="csrresult2" id="csrresult2" size="70" maxlength="120" autocomplete="off" onkeyup="translate()" />
                <input type="reset" value="Reset" onclick="csrAlpha.csrresult2.focus();" />

                <p>
                  <textarea name="csrresult" id="csrresult" class="tb7" cols="71" rows="10" value=""></textarea>
                </p>
              </form>
              </td>
        </tr>
    </table>

第一部分:导言

<script>
    var Words = {
        "b" : "Dadada",
        "bob" : "Robert",
        "flower" : "Banana",
        "brad" : "Chair"
    }


    function translate(){
        text = document.getElementById("csrresult2").value.toLowerCase();

        if(typeof Words[text] != "undefined")
            document.getElementById("csrresult").value=Words[text];
        else
            document.getElementById("csrresult").value="Text not found!";
    }
</script>




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签