我需要幫助來糾正這種混亂的情況。下面的瀏覽器聊天代碼可以作爲一個整體使用,但並不完整。HTML ::在一個標記中調用多個函數
<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>
這些腳本:
<script src="scripts/soundEngine.js"></script>
<script src="scripts/animationEngine.js"></script>
<script src="scripts/talk.js"></script>
這就要求機器人API
<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>
,這一個功能,他們都喊一次:
<script>
function triggerAll(){
doTalk();
play_song();
animate_song();
}
</script>
aperrently ,<textarea>
調用play_song()
和animate_song()
,但不叫doTalk()
有沒有辦法讓所有的函數調用在一個tag
並減少代碼?