【发布时间】:2013-01-30 23:52:35
【问题描述】:
以下两种传递/设置变量的方式有什么优缺点?
<input type="password" name="pw1" id="pw1" onkeyup="return passwordCheck(document.getElementById('pw1'), document.getElementById('pw2'))"/
function passwordCheck(first, second){...
或
<input type="password" name="pw1" id="pw1" onkeyup="return passwordCheck()"/
function passwordCheck(){
var first = document.getElementById('pw1')
var second = document.getElementById('pw2')...
【问题讨论】:
-
在第一个中,您可以使用任意两个值调用函数,而在第二个中,您将始终只检查函数内部元素的值。除此之外,我想不出任何赞成/反对。
标签: javascript html function argument-passing