我的 INPUT 表单的 ENTER 键问题得到解决,并且显示了一个 JavaScript alert() 框:
jQuery CSS Selector to Filter keyboard ENTER key
alert() 框不漂亮,我一直在集成一个叫做 Cool notification messages with CSS3 and jQuery 的东西.
在Dhiraj's Demo ,这些通知消息在单击超链接时触发,但我看不到他如何连接他的 click
事件或调用他的 showMessage
函数。
会不会是他的文档加载方法的这段代码?
$(document).ready(function() {
// ...
$('.message').click(function() {
$(this).animate({top: -$(this).outerHeight()}, 500);
});
});
因为我没有得到上面的部分,所以我不知道如何修改下面的 jQuery 部分以用他正在使用的内容替换 alert() 框:
$('container content input').keypress(function (e) {
if (e.which == 10 || e.which == 13) {
alert('Form Submission needs to occur using the Submit button.');
e.preventDefault();
}
});
我想看看如何修改它,而不是alert(),这样我就可以说:
$('.container .content .row input').keypress(function (e) {
if (e.which == 10 || e.which == 13) {
//alert('Form Submission needs to occur using the Submit button.');
$(this).animate({top: -$(this).outerHeight() }, 500);
return false;
}
});
我如何传递一个值来指示我想使用哪种样式的框?
我如何将我的文本(“需要使用提交按钮进行表单提交。”)传递给标签?
最佳答案
这是绑定(bind)到 click
的代码片段:
$('.'+ type +'-trigger').click(function(){
hideAllMessages();
$('.'+type).animate({top:"0"}, 500);
});
您可以简单地将事件处理程序更改为您的回车键:
$('container content input').keypress(function (e) {
var type = 'error'; // use error message by default
if (e.which == 10 || e.which == 13) {
hideAllMessages();
$('.' + type).animate({top:"0"}, 500);
e.preventDefault();
}
});
然后您需要将错误信息放入错误 div 中:
<div class="error message">
<h3>Ups, an error ocurred</h3>
<p>This is just an error notification message.</p>
...或者您也可以从 Javascript 传递消息:
hideAllMessages();
$('.' + type).find('h3').html('Your error title');
$('.' + type).find('p').html('Your error message');
$('.' + type).animate({top:"0"}, 500);
P.S. - 当您点击消息(关闭它)时,这里的代码是绑定(bind)的,而不是创建它的按钮:
$(document).ready(function() {
// ...
$('.message').click(function() {
$(this).animate({top: -$(this).outerHeight()}, 500);
});
});
关于jquery - 如何触发我的 jQuery 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20388019/