Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

图片描述
为什么这种写法不行?请问错在哪了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
361 views
Welcome To Ask or Share your Answers For Others

1 Answer

首先,不要发截图,我想修改你代码都不可以。
其次吧,onclick是回调函数,当class=‘jisuan’触发onclick事件时,并不会传给你参数n,而且你这种写法永远不会到

    answer.innerHTML = factorial(n)

这条语句。
可以改成这样写 :

    jisuan.onclick = function() {
        var n = document.getElementById('jieceng').value
         
         function factorial(n) {
             if( n > 1){
                 //你的代码
             }else {
                 //你的代码
             }
         } 
         answer.innerHTML = factorial(n)   
    }

再也不给发截图的写代码了(逃)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...