警报命令采用以下结构:
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/