我有两个 JavaScript 程序,一个是我在旧公司中使用的,另一个是我刚刚在网站上遇到的。今天,我注意到我的同事在程序中使用了这两个标准,在最终确定产品之前,我们必须将所有内容更改为一个标准代码。
<script type="text/javascript">
// Reference the textbox
var txt = document.getElementById("<%=txtName.ClientID%>");
// If the textbox was found, call its focus function
if (txt != null)
txt.focus();
</script>
或者
<script type="text/javascript">
// Reference the textbox and call its focus function
var txt = $("#txtName");
txt.focus();
</script>
如果您处于这种情况,您会建议哪一种,为什么?