我想动态地将一个按键处理程序添加到输入中。
<apex:commandButton value="Approve" onclick="validateCAMDiv1('ApproveId') && fraudCheck();" action="{!approve}" />
&#13;
$("#m1rename").click(function() {
$('#modalinput').val('').keypress(function(event) {
if (event.keycode === 13) {
renameabc(); // this function name should be changed dinamically, based on `m1rename` click.
}
});
});
function renameabc() {
alert('abc');
}
function renamedef() {
alert('def');
}
&#13;
如果在<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='modal'>
<form id='modalform' autocomplete='off'>
<input type='text' id='modalinput'>
</form>
<div class='modalbtn' id='modalok' onclick=''>OK</div>
<div class='modalbtn' id='modalcancel' onclick=''>CANCEL</div>
<div class='clear'></div>
</div>
内按下回车键,我希望显示提醒,但它不起作用。
答案 0 :(得分:0)
如果要在输入中动态添加按键监听器,可以这样做:
$("#m1rename").click(function() {
var funcName = $(this).val(); //this takes the value from m1rename. Use .text() if .val() don't work.
$('#modalinput').val('').keypress(function(event) {
if (event.keycode === 13) {
funcName(); // this function name should be changed dinamically, based on `m1rename` click.
}
});
});
function renameabc() {
alert('abc');
}
function renamedef() {
alert('def');
}
答案 1 :(得分:-2)
尝试下面的代码,当你在文本框中按回车键然后它显示警告信息时,它的工作正常。
class 01