如何设置 OnClientClick 值 - 语法?

How to set the OnClientClick value - syntax?

ASP.NET 在 VB.NET 中编码 -- Web 应用程序。 我问了几个关于 "proper way" 的问题,以便在 aspx 按钮声明中设置 OnClientClick 短语。

选项 1:以 'javascript:' 开头并围绕 {...}

中的 js
<asp:Button ID="btnDelete" runat="server" CausesValidation="False"  SkinID="cmdButton" style="margin-left: 2em;"
   CommandName="Delete" Text="Delete" 
   OnClientClick = "javascript:{(!confirm('Do you want to delete this record?'); return false;}"

选项 2:不以 'javascript:' 开头并且不包围 {...}

中的 js
<asp:Button ID="btnDelete" runat="server" CausesValidation="False"  SkinID="cmdButton" style="margin-left: 2em;"
   CommandName="Delete" Text="Delete" 
   OnClientClick="if (!confirm('Do you want to delete this record?')) return false;"

这两个选项似乎在 IE-10 中都能正常工作,但还没有尝试过其他浏览器。所以我很好奇不同的短语。

'javascript:'的前导怎么样? -- 这有什么影响?

用 {...} 包围 js 有什么影响?

欢迎您提出意见 -- 构建短语的最佳方式是什么。

欢迎任何其他语法(或风格)或建议。

提前谢谢...约翰

OnClientClick 呈现为标准 HTML onclick 属性,因此请放入任何适用的内容。

即- 不需要 javascript 前缀,也不需要括号。