我正在关注 this教程并具有以下代码:
CSS:
.bot {
color:#CCCCCC;
font-weight:bold;
}
Javascript:
function username(){
$("#container").html("<span class = 'bot'>Chatbot: </span>Hello, what is your name?);
}
$(function(){
username();
});
我已完全按照教程进行操作,但不知道为什么代码无法正常工作。有谁知道可能是什么问题?
最佳答案
您在 username
函数中缺少引号 "
以关闭 html 字符串:
function username() {
$("#container")
.html("<span class = 'bot'>Chatbot: </span>Hello, what is your name?");
}
$(function() {
username();
});
这样的错误将显示在您的浏览器调试控制台中。
关于javascript - 为什么 jQuery 聊天机器人的这段代码不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21062588/