[英]JQuery onclick do something … after click alert
我正在使用此代碼:
onclick="$('#default').click();"
...如果成功完成,有沒有辦法回復某事的警報?
更新:
這里似乎有問題:
onclick="$('#default').click( function() { alert('clicked'); });"
那句法有點過時了。 通常你會像這樣使用jQuery的click()
:
HTML:
<a id="something">Text</a>
JavaScript的:
$('#something').click( function() { alert('clicked'); });
更新:
即使您更新的代碼似乎也可以工作,但是代碼非常糟糕 - 您的javascript或DOM結構中的其他地方可能會有一些錯誤。 見http://jsfiddle.net/HCQeN/1/
從onclick中分離jquery會好得多,例如: http : //jsfiddle.net/ctUgp/
讓我們說你的例子是:
<input type="button" id="myButton" onClick="$('#default').click()" />
你想要的是:
<input type="button" id="myButton" />
<script type="text/javascript">
$(document).ready(function(){
// this code will run when the document has loaded
// and all elements are in place
$("#myButton").click(function(){
// this code will be run when the user clicks on
// the button we created above
$('#default').click(); // this calls the click event on #default
alert('Finished'); // now it is finished
}); // close the click handler on #myButton
$('#default').click(function(){
// this code will be run when the user click on
// the element with id "default" OR (in this case)
// when the click event is triggered from clicking the
// button above.
alert('#default was clicked');
}); // close the click handler on #default
}); // close the document.ready code block.
</script>
像這樣
$('#default').click( function() {
alert('Handler for .click() called.');
} );
嘗試:
onclick="$('#default').click(function() { alert('foobar'); });"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.