我创建了一个输入框,它通过tab键进行验证。但是当要按下输入按钮时需要进行验证。
function checktxt(h, v, w, c) {
var th = $("#" + h).val();
var tv = $("#" + v).val();
if (th.toLowerCase() == tv.toLowerCase()) {
$("." + c).show();
$("." + w).hide();
var win = new Audio('audio/wright.mp3');
} else if (tv.toLowerCase() == "") {
} else {
$("." + c).hide();
$("." + w).show();
//setTimeout(function() { $( "."+w ).hide(); }, 5000);
var win = new Audio('audio/wrong.mp3');
}
win.play();
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="position:absolute; margin-left:350px;top:226px;">
<input id="texthidden1" type="hidden" value="413" />
<input id="textvisible1" type="text" value="" style="font-size:32px;text-align:center;border:0px solid black;height:50px;width:100px;" maxlength="4" onblur="javascript:checktxt('texthidden1','textvisible1','wrong1','correct1');" />
<div class="wrong1" style="margin-left: 120px;margin-top: -30px; position:absolute; float:left; display: none; margin-bottom:-30px; ">
<img src="../images/smallwrong.png" />
</div>
<div class="correct1" style="position:absolute;margin-left: 120px; margin-top: -30px; float:left; display: none; margin-bottom:-30px;">
<img src="../images/smallgreen.png" />
</div>
</div>
&#13;
答案 0 :(得分:2)
您可以在检测到按下回车键时执行验证。
$(document).keypress(function(e) {
if(e.which == 13) {
// enter pressed now validate
checktxt(h,v,w,c)
}
});
答案 1 :(得分:2)
输入内部输入类型
$("#textvisible1").on('keyup', function (e) {
if (e.keyCode == 13) {
// your code here
}
});
答案 2 :(得分:1)
建议使用saperate功能输入按键和标签。
dgv_Transations.Loaded += (s, e) =>
{
if (dt.Rows.Count > 0)
{
var lastItem = dt.DefaultView[dt.Rows.Count - 1];
DataGridRow r = dgv_Transations.ItemContainerGenerator.ContainerFromItem(lastItem) as DataGridRow;
if (r == null)
{
dgv_Transations.ScrollIntoView(lastItem);
r = dgv_Transations.ItemContainerGenerator.ContainerFromItem(lastItem) as DataGridRow;
}
r.Background = Brushes.Red;
}
};
的javascript
<input type="text" onkeypress="return runScript(event)" onblur="javascript:checktxt('texthidden1','textvisible1','wrong1','correct1');" />