js给onclick赋值传参数的两种方法

时间:2013-11-25    点击:99   
1)当方法没有参数时,赋值可以直接用onclick = 方法名
复制代码 代码如下:

  window.onload = function() {
        $('btnTest').onclick = test;  
  }
  function test() {
        alert(val);
  }

2)当方法有参数时,用onclick = 方法名(参数)时就有错了,需要在方法名前面加function()
复制代码 代码如下:

  window.onload = function() {
        $('btnTest').onclick = function() { test(1) };  
  }
  function test(val) {
        alert(val);
  }
正则表达式中特殊符号及正则表达式的几种方法总结(replace,test,search)
jquery简单实现滚动条下拉DIV固定在头部不动
整理的比较全的event对像在ie与firefox浏览器中的区别
javascript利用apply和arguments复用方法
javascript模拟实现C# String.format函数功能代码
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved