0

我想创建一个函数并在单击按钮时调用该函数。互联网上有很多指南可以做到这一点,但它只是没有用。(我是初学者)

<script type = "javascript/text">
var name = function()
name = prompt ("Who are you?", "");
alert ("hello" + " " + name);
</script>

我怎么称呼“名字”?

4

1 回答 1

0

I changed your code into this:

<script>
     var name = prompt ("Who are you?", "");
    alert ("hello" + " " + name);
</script>

This should work. You don't even need a function here.

But if you want to store a function in a variable and then call it, just do:

var myFunction = function() {
    // function body
}
myFunction(); // calling it!
于 2013-01-28T16:57:55.447 回答