恼人的this.refresh()不是Firefox中的一个功能

时间:2011-02-05 14:19:52

标签: javascript refresh

这是我的问题的解决方案。我可以显示一个字段,输入一个新值,再次单击该字段,然后使用新值使该字段消失。每当this.refresh()不是函数时,Firefox错误控制台就会抱怨。

如何摆脱this.refresh()不是函数错误,以便我可以清除我的Firefox控制台并查找实际导致问题的错误?

var gotIt='no'

function askName(x)
 {if(gotIt=='yes')
   {response=this.name
    characters[x].setName(response)
    gotIt='no'
   }
  else
   {gotIt='no'
    this.name=characters[x].name
    response="<input onClick=_setName(this.value) size=10 type=text value="+this.name+">"
    characters[x].setName(response)
   }
 }
function _setName(x)
 {this.name=x
  this.refresh()
  gotIt='yes'
 }

1 个答案:

答案 0 :(得分:2)

代码中的几乎所有内容都是错误的,以下代码可以满足您的需求。如果你想了解javascript,你需要努力。

enter image description here

<!doctype html>

<html>
    <head>
        <script>
            window.onload = function () {
                var input = document.createElement ("input");
                var span = document.getElementsByTagName ("span")[0];

                input.addEventListener ("blur", function () {
                    span.innerHTML = this.value;
                }, false);

                span.addEventListener ("click", function () {
                    if (this.getElementsByTagName ("input").length === 0) {
                        input.value = this.textContent;

                        this.innerHTML = "";

                        this.appendChild (input);

                        input.focus ();
                    }
                }, false);
            }
        </script>

        <style>
            span {
                font-weight: bold;
            }
        </style>

        <title></title>
    </head>

    <body>
        <span>Braveheart</span>
    </body>
</html>