按下按钮时调用js函数
Call js function when button is pressed
我想在按下按钮时调用一个js函数。看完this and this, I did something like this in the jsFiddle。但是,当我按下按钮时,没有任何反应!我错过了什么?
js代码:
jQuery(document).ready(function() {
$('#ref1').keypress(function() {
alert('Handler for .keypress() called.');
});
});
你不能在 <a>
元素上有 keypress
事件,使用 click
jQuery(document).ready(function() {
$('#ref1').click(function() {
alert('Handler for .click() called.');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<div data-role="page" id="pageone">
<div data-role="main" class="ui-content">
<a href="#" id="ref1" title="Refresh page if you did shit" data-role="button" data-icon="refresh" data-iconpos="notext" data-theme="b" data-inline="true" class="ui-link ui-btn ui-btn-b ui-icon-refresh ui-btn-icon-notext ui-btn-inline ui-shadow ui-corner-all"
role="button">
<p>Refresh page (helpful in case of mistake)</p>
</a>
</div>
</div>
我想在按下按钮时调用一个js函数。看完this and this, I did something like this in the jsFiddle。但是,当我按下按钮时,没有任何反应!我错过了什么?
js代码:
jQuery(document).ready(function() {
$('#ref1').keypress(function() {
alert('Handler for .keypress() called.');
});
});
你不能在 <a>
元素上有 keypress
事件,使用 click
jQuery(document).ready(function() {
$('#ref1').click(function() {
alert('Handler for .click() called.');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<div data-role="page" id="pageone">
<div data-role="main" class="ui-content">
<a href="#" id="ref1" title="Refresh page if you did shit" data-role="button" data-icon="refresh" data-iconpos="notext" data-theme="b" data-inline="true" class="ui-link ui-btn ui-btn-b ui-icon-refresh ui-btn-icon-notext ui-btn-inline ui-shadow ui-corner-all"
role="button">
<p>Refresh page (helpful in case of mistake)</p>
</a>
</div>
</div>