<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="JS/jquery-1.3.2.1.min.js"></script>
<script type="text/javascript">
$(function()
{
$("[type=button]").click(function()
{
alert('1');
});
});
</script>
</head>
<body>
<input type="button" value="测试" onclick="alert('2')" />
</body>
</html>像上面点击后是先执行 alert('2') 再执行 alert('1')
有没有办法先执行 alert('1')再执行alert('2')
或者说Jquery有没有方法如$("[type=button]").beforeclick(function(){});谢谢
可以这样: var fun=$("[type=button]")[0].onclick;
$("[type=button]")[0].onclick=function() {
alert("1");
fun();
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="JS/jquery-1.3.2.1.min.js"></script>
<script type="text/javascript">
$(function()
{
var cmdtest= $("[type=button]"),
_onclick = _cmdtest.attr("onclick");
_cmdtest.attr("onclick","").click(function(){
alert(1);
eval(_onclick)();
});
});
</script>
</head>
<body>
<input type="button" value="测试" onclick="alert('2')" />
</body>
</html>