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.
我有这样的代码
if(itemid){ expandHighlight(itemid); } function expandHighlight(itemid){ alert(itemid); }
当然,它可以正常工作,但是如果 itemid 的值为“0”(int) - 什么也没有发生。A get no alert, just nothing... 有什么想法吗?
这是因为它if ("0")是虚假的,它不会调用该expandHighlight函数。
if ("0")
expandHighlight
要么让你if更明智:
if
if(itemid !== undefined)
或将其完全删除