javascript 或 jquery : show multiple variables in one alert

标签 javascript jquery alert

警报命令采用以下结构:

alert (variable)

如何在单个警报中显示多个变量?

最佳答案

Alert command assumes this structure: alert (variable)

不,alert() 采用这种结构:

    alert(some expression)

...where "some expression" is pretty much any JavaScript expression - if the expression is not a string it will be converted (though in some cases, e.g., for some objects the result might not be very meaningful).

So:

alert(variable);
alert("string literal");
alert(variable1 + variable2 + variable3);
alert(variable1 + ", " + variable2);
alert(resultOfFunctionCall());
alert([1,2,3]);
alert(whatever() + "else" + you.can.think + "of");

甚至:

alert();   // displays "undefined"

请注意,如果您尝试调试代码,最好使用 console.log()alert()。如果您尝试生成动态消息以向用户显示,只需根据需要连接变量,例如:

alert("Hello there " + name + ". Welcome.");

关于javascript 或 jquery : show multiple variables in one alert,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18093782/

相关文章:

javascript - 使用匹配的正则表达式字符,我怎样才能得到它的大写等效字符?

javascript - 如何使用php获取选择框的数组值作为ajax函数中的数组

javascript - 获取选定的节点 ID

javascript - 如何在浏览器的警告框上显示大文本并防止文本被剪裁?

java - 使用 Selenium 接受 Windows 安全警报

ios - NSTimer火特定代码,而不是选择器

javascript - MVC : Ajax data not getting to Controller

javascript - 本地存储的大小不合逻辑

javascript - JS :Want to animate on clicking the button

javascript - JQuery 库中的特殊值(value)