Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试评估像a == b ? 'Ok' : 'Cancel';使用 JavaScript这样的表达式,eval()但显示错误。
a == b ? 'Ok' : 'Cancel';
eval()
有什么方法可以执行并返回字符串eval()吗?
问候, Nwbrd
您的错误可能与调用之前有关a或b未定义eval(),例如:以下代码在eval()调用按预期返回字符串时正常工作。
a
b
var a = 5, b = 6; var result = eval("a == b ? 'SAME' : 'DIFFERENT'"); alert(result);