javascript中使用的变量,未定义。需要澄清

时间:2017-05-07 21:26:49

标签: javascript firefox-addon firefox-addon-sdk

我是Javascript的新手。我从documentation找到了这段代码:

// When the user hits return, send the "text-entered"
// message to main.js.
// The message payload is the contents of the edit box.
var textArea = document.getElementById("edit-box");
textArea.addEventListener('keyup', function onkeyup(event) {
  if (event.keyCode == 13) {
    // Remove the newline.
    text = textArea.value.replace(/(\r\n|\n|\r)/gm,"");
    addon.port.emit("text-entered", text);
    textArea.value = '';
  }
}, false);
// Listen for the "show" event being sent from the
// main add-on code. It means that the panel's about
// to be shown.
//
// Set the focus to the text area so the user can
// just start typing.
addon.port.on("show", function onShow() {
  textArea.focus();
});

我想知道text变量是否有问题?如何在没有定义的情况下使用它?这在Javascript中是否可以接受?你能澄清一下吗?

0 个答案:

没有答案