2012-09-19 25 views
0

这是我的HTML和jQuery代码。当我点击按钮时,我没有从浏览器得到任何回应。jQuery:提交选择器不加载

<html> 
<head> 
<title>jQuery Test</title> 

    <script type="text/javascript" src="js/jquery.js"></script> 
    <script type="text/javascript" src="js/toggle.js"></script> 

</head> 

<body> 


    <input type="submit" value="button"> 
</body> 
</html> 

jQuery的

$(':submit').click(function() { 
    // Act on the event 
    $('submit').attr('Please wait', 'value') 
}); 

网上的教程,我以下。

enter image description here

+1

fyi':submit'已被弃用http://api.jquery.com/category/deprecated/ –

+0

哇,所以很难保持更新所有这一切哈哈。 Thanks @wirey。 – AppSensei

回答

1

你应该参考$(this)您的回调中:

$(':submit').click(function() { 
    // Act on the event 
    $(this).attr('value', 'Please wait') 
}); 

无论如何,一个<input><form>元素的一部分 - 你应该submit活动形式本身的约束,而不是一个单一的元素。

如果你只是想要一个按钮,坚持<button>

+0

选择器确实存在:http://api.jquery.com/submit-selector/ –

+0

它适用于在线教程的人。 – AppSensei

+0

'$('submit')。attr('Please wait','value')'不起作用。将其更改为'$(this).attr('value','Please wait')' – Giona

0
$("input[type='submit']").click(function() { 
    // Act on the event 
    $(this).val('Please wait'); 
}); 

应该这样做。