我有一个 aspx 表单,我需要使用 jquery 或 javascript 进行验证。
如果用户输入的值在该文本框中无效,我只想在文本框附近给出一条消息。为了在弹出窗口中显示该消息[notalert('message')]
如何找到用户输入无效数据的文本框的位置,或者如何使用 javascript 或 jquery 在文本框附近显示消息?
我需要在模糊的情况下进行验证。这样用户在输入后很容易知道他是否输入了有效的数据。
提前致谢。我对使用 asp.net ajax 验证及其标注扩展器不感兴趣。
我只是想实现一个类似于验证标注扩展器的功能。
最佳答案
当你将模糊事件绑定(bind)到文本框时,你就知道它是哪个文本框。只需使用您的回调 javascript 在附近插入错误即可。
如果你正在使用 jquery,它可能看起来像:
$('.my_textboxes').blur(function() {
var textbox = $(this);
//ajax validation call
$.post('/whereever', {}, function(response) {
//ajax callback
if (response == 'error') {
textbox.next().html(error); //something like this to insert the error into the next element after the texrbox, eg, a span to hold the error
}
});`
关于javascript - 使用 Javascript 在文本框中显示消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4246771/