2016-07-05 7 views
0

私はこの乱雑な状況をまっすぐにするのに助けが必要です。ブラウザチャットの次のコードは全体として機能しますが、うまくはありません。HTML :: 1つのタグで多くの関数を呼び出す

<p>chat in silence:</p> 
<input id="yousay" name="input" size="52" onkeydown="if (event.keyCode == 13) { doTalk(); }"/> 

<p>chat in with music:</p> 
<textarea onfocus="clearContents(this);" id="chat" cols="50" rows="2" ></textarea> 

<button type="button" onclick="triggerAll();">answer</button> 

これらはスクリプトです:

aperrently
<script> 
     function triggerAll(){ 
     doTalk(); 
     play_song(); 
     animate_song(); 
     } 
</script> 

<script src="scripts/soundEngine.js"></script> 
<script src="scripts/animationEngine.js"></script> 
<script src="scripts/talk.js"></script> 

これは

<script> 
    var pb = new Pandorabot("aiaas.pandorabots.com", 'validid', 'validname', 'validid'); 
    function doTalk() { 
    var input = document.getElementById("yousay").value; 
    document.getElementById("yousay").value = ""; 
    pb.talk(input, function(data) { 
     var response = data["responses"]; 
     document.getElementById("response").innerHTML = response; 
     console.log(response); 
    }); 
    } 
</script> 

と、この一度にすべてを呼び出す関数ボットのAPIを呼び出します、<textarea>play_song()animate_song()が呼び出されますが、doTalk()

すべての関数呼び出しを1つのコードに入れてコードを減らす方法はありますか?

答えて

1

htmlでは、すべてを呼び出す関数を呼び出すことができます。あなたのような は、スクリプト1、2、3を持っていて、ここでこの

<randomtag onclick="call_all()"></randomtag> 

<script type="text/javascript"> 
    function call_all(){ 
    one(); 
    two(); 
    three(); 
    } 
</script> 
0
var pb = new Pandorabot("aiaas.pandorabots.com", 'validid', 'validname', 'validid'); 

引数が有効なのですか?この引数が有効でない場合、関数doTalk()は存在せず、呼び出すことはできません

関連する問題