jquery对比验证的问题 急

DT4261541 2013-11-18 04:19:21

如上图所示,如何实现用户每输入一个字符判断是否正确。
<div id="d_spell">
<input id="spell" title="" name="spell" class="input wide" type="text" validateurl="{config.webpath}tools/submit_ajax.ashx?action=validate_username"/>
</div>

我将正确答案通过jquery赋值到title里,如何动态让title里的值与用户输入的值作对比,正确后关闭这个弹出层
...全文
343 26 打赏 收藏 转发到动态 举报
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzb0712 2013-11-19
  • 打赏
  • 举报
回复

<script type="text/javascript" src="{config.templateskin}/js/jquery-webox.js"></script>
<script type="text/javascript">
    
    $(document).ready(function () {
       
        $('#inside').click(function () {
            $.webox({
                height: 188,
                width: 400,
                bgvisibel: true,
                title: '内嵌弹出层调用',
                html: $("#pingxie").html()
            });
        });

        
        $("#spell").keyup(function () {

            var aaa = $("#spell").attr("title");
            var bbb = $("#spell").attr("value");
            if (aaa == bbb) {
                alert("相同");
            }
            else {
                alert("不同");
            }
        });
    })
    </script>
</head>
<body>
<a  href="javascript:void(0);" id="inside" ><strong>单词拼写</strong></a>
<div id="pingxie" style="display:none;">
 <div>
<input id="spell" title="123" name="spell" class="input wide" type="text" />
</div>
</div>
</body>
将你的input标签的id换成class, $('#inside').click(function () { $.webox({ height: 188, width: 400, bgvisibel: true, title: '内嵌弹出层调用', html: $("#pingxie").html() }); });这个调用里面的html后面改为:$("#pingxie").clone(); 这个键盘事件#改为.就可以了 $("#spell").keyup(function () { var aaa = $("#spell").attr("title"); var bbb = $("#spell").attr("value"); if (aaa == bbb) { alert("相同"); } else { alert("不同"); } });
DT4261541 2013-11-19
  • 打赏
  • 举报
回复
 function upperCase() {
var aaa = $("#spell").attr("title");
var bbb = $("#spell").val();
if (aaa == bbb) {
alert("相同");
}
else {
alert("不同");
}
}

<a  href="javascript:void(0);" id="inside" ><strong>单词拼写</strong></a>
<div id="pingxie" style="display:none;">
<div>
<input id="spell" title="123" name="spell" class="input wide" type="text" onkeyup="upperCase()"/>
<div id="aaa"></div>
</div>
</div>


这样写可以了 但是var bbb = $("#spell").val();老是取不到文本框的值

DT4261541 2013-11-19
  • 打赏
  • 举报
回复
引用 18 楼 u011461314 的回复:
好复杂啊。
我只想在弹出层里调用keyup方法判断一下值是否正确
zhjdg 2013-11-19
  • 打赏
  • 举报
回复
好复杂啊。
DT4261541 2013-11-19
  • 打赏
  • 举报
回复
$('body').append('<div class="background" style="display:none;"></div><div class="webox" style="width:' + width + 'px;height:' + height + 'px;display:none;"><div id="inside" style="height:' + height + 'px;"><h1 id="locked" onselectstart="return false;">' + (option['title'] ? option['title'] : 'webox') + '<a class="span" href="javascript:void(0);"></a></h1>' + (option['iframe'] ? '<iframe class="w_iframe" src="' + option['iframe'] + '" frameborder="0" width="100%" scrolling="yes" style="border:none;overflow-x:hidden;height:' + parseInt(height - 30) + 'px;"></iframe>' : option['html'] ? option['html'] : '') + '</div></div>');
			$("#spell").bind("keyup", function () {
			    var aaa = $("#spell").attr("title");
			    var bbb = $("#spell").attr("value");
			    if (aaa == bbb) {
			        alert("相同");
			    }
			    else {
			        alert("不同");
			    }
			});
这样也不对
DT4261541 2013-11-19
  • 打赏
  • 举报
回复
19行里的base.js里面写的就是keyup方法 还是不行啊
sliwey 2013-11-19
  • 打赏
  • 举报
回复
引用 14 楼 DT4261541 的回复:
[quote=引用 13 楼 u011559804 的回复:] [quote=引用 12 楼 DT4261541 的回复:] [quote=引用 11 楼 crazypandariy 的回复:] 使用浏览器调试看看。还有,把完整页面代码贴出来,你这样就俩段代码看不出问题在哪里,因为你写的js没有语法错误
<script type="text/javascript" src="{config.templateskin}/js/jquery-webox.js"></script>
<script type="text/javascript">
    
    $(document).ready(function () {
       
        $('#inside').click(function () {
            $.webox({
                height: 188,
                width: 400,
                bgvisibel: true,
                title: '内嵌弹出层调用',
                html: $("#pingxie").html()
            });
        });

        
        $("#spell").keyup(function () {

            var aaa = $("#spell").attr("title");
            var bbb = $("#spell").attr("value");
            if (aaa == bbb) {
                alert("相同");
            }
            else {
                alert("不同");
            }
        });
    })
    </script>
</head>
<body>
<a  href="javascript:void(0);" id="inside" ><strong>单词拼写</strong></a>
<div id="pingxie" style="display:none;">
 <div>
<input id="spell" title="123" name="spell" class="input wide" type="text" />
</div>
</div>
</body>
jquery-webox.js 代码
$.extend({
	webox:function(option){
		var _x,_y,m,allscreen=false;
		if(!option){
			alert('options can\'t be empty');
			return;
		};
		if(!option['html']&&!option['iframe']){
			alert('html attribute and iframe attribute can\'t be both empty');
			return;
		};
		option['parent']='webox';
		option['locked']='locked';
		$(document).ready(function(e){
			$('.webox').remove();
			$('.background').remove();
			var width=option['width']?option['width']:400;
			var height=option['height']?option['height']:240;
            $('body').append('<script type="text/javascript" src="/templates/green/js/base.js"></script>');
			$('body').append('<div class="background" style="display:none;"></div><div class="webox" style="width:'+width+'px;height:'+height+'px;display:none;"><div id="inside" style="height:'+height+'px;"><h1 id="locked" onselectstart="return false;">'+(option['title']?option['title']:'webox')+'<a class="span" href="javascript:void(0);"></a></h1>'+(option['iframe']?'<iframe class="w_iframe" src="'+option['iframe']+'" frameborder="0" width="100%" scrolling="yes" style="border:none;overflow-x:hidden;height:'+parseInt(height-30)+'px;"></iframe>':option['html']?option['html']:'')+'</div></div>');
			if(navigator.userAgent.indexOf('MSIE 7')>0||navigator.userAgent.indexOf('MSIE 8')>0){
				$('.webox').css({'filter':'progid:DXImageTransform.Microsoft.gradient(startColorstr=#55000000,endColorstr=#55000000)'});
			}if(option['bgvisibel']){
				$('.background').fadeTo('slow',0.3);
			};
			$('.webox').css({display:'block'});
			$('#'+option['locked']+' .span').click(function(){
				$('.webox').css({display:'none'});
				$('.background').css({display:'none'});
			});
			var marginLeft=parseInt(width/2);
			var marginTop=parseInt(height/2);
			var winWidth=parseInt($(window).width()/2);
			var winHeight=parseInt($(window).height()/2.2);
			var left=winWidth-marginLeft;
			var top=winHeight-marginTop;
			$('.webox').css({left:left,top:top});
			$('#'+option['locked']).mousedown(function(e){
				if(e.which){
					m=true;
					_x=e.pageX-parseInt($('.webox').css('left'));
					_y=e.pageY-parseInt($('.webox').css('top'));
				}
				}).dblclick(function(){
					if(allscreen){
						$('.webox').css({height:height,width:width});
						$('#inside').height(height);
						$('.w_iframe').height(height-30);
						$('.webox').css({left:left,top:top});
						allscreen = false;
					}else{
						allscreen=true;
						var screenHeight = $(window).height();
						var screenWidth = $(window).width();$
						('.webox').css({'width':screenWidth-18,'height':screenHeight-18,'top':'0px','left':'0px'});
						$('#inside').height(screenHeight-20);
						$('.w_iframe').height(screenHeight-50);
					}
				});
			}).mousemove(function(e){
				if(m && !allscreen){
					var x=e.pageX-_x;
					var y=e.pageY-_y;
					$('.webox').css({left:x});
					$('.webox').css({top:y});
				}
			}).mouseup(function(){
				m=false;
			});
			$(window).resize(function(){
				if(allscreen){
					var screenHeight = $(window).height();
					var screenWidth = $(window).width();
					$('.webox').css({'width':screenWidth-18,'height':screenHeight-18,'top':'0px','left':'0px'});
					$('#inside').height(screenHeight-20);
					$('.w_iframe').height(screenHeight-50);
				}
			});
	}
});
我弹出的DIV也是在同一个页面里啊 为什么没有办法调用keyup方法呢? 调试根本就没执行keyup方法 是不是html: $("#pingxie").html()写的有问题呢。大家帮我看看吧[/quote] 在19行后面加上keyup事件看看[/quote] 具体要怎么加 我初学jquery不是很懂你的意思 我17行不是已经加了keyup事件了吗?只要不是弹出层就不会有问题[/quote] 加在这个文件里jquery-webox.js $('body').append()源文件里在这加了一大段html代码 应该就是弹出层的html 你把事件绑定放到这里试下看看 我也不知道对不对
DT4261541 2013-11-19
  • 打赏
  • 举报
回复
引用 13 楼 u011559804 的回复:
[quote=引用 12 楼 DT4261541 的回复:] [quote=引用 11 楼 crazypandariy 的回复:] 使用浏览器调试看看。还有,把完整页面代码贴出来,你这样就俩段代码看不出问题在哪里,因为你写的js没有语法错误
<script type="text/javascript" src="{config.templateskin}/js/jquery-webox.js"></script>
<script type="text/javascript">
    
    $(document).ready(function () {
       
        $('#inside').click(function () {
            $.webox({
                height: 188,
                width: 400,
                bgvisibel: true,
                title: '内嵌弹出层调用',
                html: $("#pingxie").html()
            });
        });

        
        $("#spell").keyup(function () {

            var aaa = $("#spell").attr("title");
            var bbb = $("#spell").attr("value");
            if (aaa == bbb) {
                alert("相同");
            }
            else {
                alert("不同");
            }
        });
    })
    </script>
</head>
<body>
<a  href="javascript:void(0);" id="inside" ><strong>单词拼写</strong></a>
<div id="pingxie" style="display:none;">
 <div>
<input id="spell" title="123" name="spell" class="input wide" type="text" />
</div>
</div>
</body>
jquery-webox.js 代码
$.extend({
	webox:function(option){
		var _x,_y,m,allscreen=false;
		if(!option){
			alert('options can\'t be empty');
			return;
		};
		if(!option['html']&&!option['iframe']){
			alert('html attribute and iframe attribute can\'t be both empty');
			return;
		};
		option['parent']='webox';
		option['locked']='locked';
		$(document).ready(function(e){
			$('.webox').remove();
			$('.background').remove();
			var width=option['width']?option['width']:400;
			var height=option['height']?option['height']:240;
            $('body').append('<script type="text/javascript" src="/templates/green/js/base.js"></script>');
			$('body').append('<div class="background" style="display:none;"></div><div class="webox" style="width:'+width+'px;height:'+height+'px;display:none;"><div id="inside" style="height:'+height+'px;"><h1 id="locked" onselectstart="return false;">'+(option['title']?option['title']:'webox')+'<a class="span" href="javascript:void(0);"></a></h1>'+(option['iframe']?'<iframe class="w_iframe" src="'+option['iframe']+'" frameborder="0" width="100%" scrolling="yes" style="border:none;overflow-x:hidden;height:'+parseInt(height-30)+'px;"></iframe>':option['html']?option['html']:'')+'</div></div>');
			if(navigator.userAgent.indexOf('MSIE 7')>0||navigator.userAgent.indexOf('MSIE 8')>0){
				$('.webox').css({'filter':'progid:DXImageTransform.Microsoft.gradient(startColorstr=#55000000,endColorstr=#55000000)'});
			}if(option['bgvisibel']){
				$('.background').fadeTo('slow',0.3);
			};
			$('.webox').css({display:'block'});
			$('#'+option['locked']+' .span').click(function(){
				$('.webox').css({display:'none'});
				$('.background').css({display:'none'});
			});
			var marginLeft=parseInt(width/2);
			var marginTop=parseInt(height/2);
			var winWidth=parseInt($(window).width()/2);
			var winHeight=parseInt($(window).height()/2.2);
			var left=winWidth-marginLeft;
			var top=winHeight-marginTop;
			$('.webox').css({left:left,top:top});
			$('#'+option['locked']).mousedown(function(e){
				if(e.which){
					m=true;
					_x=e.pageX-parseInt($('.webox').css('left'));
					_y=e.pageY-parseInt($('.webox').css('top'));
				}
				}).dblclick(function(){
					if(allscreen){
						$('.webox').css({height:height,width:width});
						$('#inside').height(height);
						$('.w_iframe').height(height-30);
						$('.webox').css({left:left,top:top});
						allscreen = false;
					}else{
						allscreen=true;
						var screenHeight = $(window).height();
						var screenWidth = $(window).width();$
						('.webox').css({'width':screenWidth-18,'height':screenHeight-18,'top':'0px','left':'0px'});
						$('#inside').height(screenHeight-20);
						$('.w_iframe').height(screenHeight-50);
					}
				});
			}).mousemove(function(e){
				if(m && !allscreen){
					var x=e.pageX-_x;
					var y=e.pageY-_y;
					$('.webox').css({left:x});
					$('.webox').css({top:y});
				}
			}).mouseup(function(){
				m=false;
			});
			$(window).resize(function(){
				if(allscreen){
					var screenHeight = $(window).height();
					var screenWidth = $(window).width();
					$('.webox').css({'width':screenWidth-18,'height':screenHeight-18,'top':'0px','left':'0px'});
					$('#inside').height(screenHeight-20);
					$('.w_iframe').height(screenHeight-50);
				}
			});
	}
});
我弹出的DIV也是在同一个页面里啊 为什么没有办法调用keyup方法呢? 调试根本就没执行keyup方法 是不是html: $("#pingxie").html()写的有问题呢。大家帮我看看吧[/quote] 在19行后面加上keyup事件看看[/quote] 具体要怎么加 我初学jquery不是很懂你的意思 我17行不是已经加了keyup事件了吗?只要不是弹出层就不会有问题
sliwey 2013-11-19
  • 打赏
  • 举报
回复
引用 12 楼 DT4261541 的回复:
[quote=引用 11 楼 crazypandariy 的回复:] 使用浏览器调试看看。还有,把完整页面代码贴出来,你这样就俩段代码看不出问题在哪里,因为你写的js没有语法错误
<script type="text/javascript" src="{config.templateskin}/js/jquery-webox.js"></script>
<script type="text/javascript">
    
    $(document).ready(function () {
       
        $('#inside').click(function () {
            $.webox({
                height: 188,
                width: 400,
                bgvisibel: true,
                title: '内嵌弹出层调用',
                html: $("#pingxie").html()
            });
        });

        
        $("#spell").keyup(function () {

            var aaa = $("#spell").attr("title");
            var bbb = $("#spell").attr("value");
            if (aaa == bbb) {
                alert("相同");
            }
            else {
                alert("不同");
            }
        });
    })
    </script>
</head>
<body>
<a  href="javascript:void(0);" id="inside" ><strong>单词拼写</strong></a>
<div id="pingxie" style="display:none;">
 <div>
<input id="spell" title="123" name="spell" class="input wide" type="text" />
</div>
</div>
</body>
jquery-webox.js 代码
$.extend({
	webox:function(option){
		var _x,_y,m,allscreen=false;
		if(!option){
			alert('options can\'t be empty');
			return;
		};
		if(!option['html']&&!option['iframe']){
			alert('html attribute and iframe attribute can\'t be both empty');
			return;
		};
		option['parent']='webox';
		option['locked']='locked';
		$(document).ready(function(e){
			$('.webox').remove();
			$('.background').remove();
			var width=option['width']?option['width']:400;
			var height=option['height']?option['height']:240;
            $('body').append('<script type="text/javascript" src="/templates/green/js/base.js"></script>');
			$('body').append('<div class="background" style="display:none;"></div><div class="webox" style="width:'+width+'px;height:'+height+'px;display:none;"><div id="inside" style="height:'+height+'px;"><h1 id="locked" onselectstart="return false;">'+(option['title']?option['title']:'webox')+'<a class="span" href="javascript:void(0);"></a></h1>'+(option['iframe']?'<iframe class="w_iframe" src="'+option['iframe']+'" frameborder="0" width="100%" scrolling="yes" style="border:none;overflow-x:hidden;height:'+parseInt(height-30)+'px;"></iframe>':option['html']?option['html']:'')+'</div></div>');
			if(navigator.userAgent.indexOf('MSIE 7')>0||navigator.userAgent.indexOf('MSIE 8')>0){
				$('.webox').css({'filter':'progid:DXImageTransform.Microsoft.gradient(startColorstr=#55000000,endColorstr=#55000000)'});
			}if(option['bgvisibel']){
				$('.background').fadeTo('slow',0.3);
			};
			$('.webox').css({display:'block'});
			$('#'+option['locked']+' .span').click(function(){
				$('.webox').css({display:'none'});
				$('.background').css({display:'none'});
			});
			var marginLeft=parseInt(width/2);
			var marginTop=parseInt(height/2);
			var winWidth=parseInt($(window).width()/2);
			var winHeight=parseInt($(window).height()/2.2);
			var left=winWidth-marginLeft;
			var top=winHeight-marginTop;
			$('.webox').css({left:left,top:top});
			$('#'+option['locked']).mousedown(function(e){
				if(e.which){
					m=true;
					_x=e.pageX-parseInt($('.webox').css('left'));
					_y=e.pageY-parseInt($('.webox').css('top'));
				}
				}).dblclick(function(){
					if(allscreen){
						$('.webox').css({height:height,width:width});
						$('#inside').height(height);
						$('.w_iframe').height(height-30);
						$('.webox').css({left:left,top:top});
						allscreen = false;
					}else{
						allscreen=true;
						var screenHeight = $(window).height();
						var screenWidth = $(window).width();$
						('.webox').css({'width':screenWidth-18,'height':screenHeight-18,'top':'0px','left':'0px'});
						$('#inside').height(screenHeight-20);
						$('.w_iframe').height(screenHeight-50);
					}
				});
			}).mousemove(function(e){
				if(m && !allscreen){
					var x=e.pageX-_x;
					var y=e.pageY-_y;
					$('.webox').css({left:x});
					$('.webox').css({top:y});
				}
			}).mouseup(function(){
				m=false;
			});
			$(window).resize(function(){
				if(allscreen){
					var screenHeight = $(window).height();
					var screenWidth = $(window).width();
					$('.webox').css({'width':screenWidth-18,'height':screenHeight-18,'top':'0px','left':'0px'});
					$('#inside').height(screenHeight-20);
					$('.w_iframe').height(screenHeight-50);
				}
			});
	}
});
我弹出的DIV也是在同一个页面里啊 为什么没有办法调用keyup方法呢? 调试根本就没执行keyup方法 是不是html: $("#pingxie").html()写的有问题呢。大家帮我看看吧[/quote] 在19行后面加上keyup事件看看
DT4261541 2013-11-19
  • 打赏
  • 举报
回复
引用 11 楼 crazypandariy 的回复:
使用浏览器调试看看。还有,把完整页面代码贴出来,你这样就俩段代码看不出问题在哪里,因为你写的js没有语法错误
<script type="text/javascript" src="{config.templateskin}/js/jquery-webox.js"></script>
<script type="text/javascript">
    
    $(document).ready(function () {
       
        $('#inside').click(function () {
            $.webox({
                height: 188,
                width: 400,
                bgvisibel: true,
                title: '内嵌弹出层调用',
                html: $("#pingxie").html()
            });
        });

        
        $("#spell").keyup(function () {

            var aaa = $("#spell").attr("title");
            var bbb = $("#spell").attr("value");
            if (aaa == bbb) {
                alert("相同");
            }
            else {
                alert("不同");
            }
        });
    })
    </script>
</head>
<body>
<a  href="javascript:void(0);" id="inside" ><strong>单词拼写</strong></a>
<div id="pingxie" style="display:none;">
 <div>
<input id="spell" title="123" name="spell" class="input wide" type="text" />
</div>
</div>
</body>
jquery-webox.js 代码
$.extend({
	webox:function(option){
		var _x,_y,m,allscreen=false;
		if(!option){
			alert('options can\'t be empty');
			return;
		};
		if(!option['html']&&!option['iframe']){
			alert('html attribute and iframe attribute can\'t be both empty');
			return;
		};
		option['parent']='webox';
		option['locked']='locked';
		$(document).ready(function(e){
			$('.webox').remove();
			$('.background').remove();
			var width=option['width']?option['width']:400;
			var height=option['height']?option['height']:240;
            $('body').append('<script type="text/javascript" src="/templates/green/js/base.js"></script>');
			$('body').append('<div class="background" style="display:none;"></div><div class="webox" style="width:'+width+'px;height:'+height+'px;display:none;"><div id="inside" style="height:'+height+'px;"><h1 id="locked" onselectstart="return false;">'+(option['title']?option['title']:'webox')+'<a class="span" href="javascript:void(0);"></a></h1>'+(option['iframe']?'<iframe class="w_iframe" src="'+option['iframe']+'" frameborder="0" width="100%" scrolling="yes" style="border:none;overflow-x:hidden;height:'+parseInt(height-30)+'px;"></iframe>':option['html']?option['html']:'')+'</div></div>');
			if(navigator.userAgent.indexOf('MSIE 7')>0||navigator.userAgent.indexOf('MSIE 8')>0){
				$('.webox').css({'filter':'progid:DXImageTransform.Microsoft.gradient(startColorstr=#55000000,endColorstr=#55000000)'});
			}if(option['bgvisibel']){
				$('.background').fadeTo('slow',0.3);
			};
			$('.webox').css({display:'block'});
			$('#'+option['locked']+' .span').click(function(){
				$('.webox').css({display:'none'});
				$('.background').css({display:'none'});
			});
			var marginLeft=parseInt(width/2);
			var marginTop=parseInt(height/2);
			var winWidth=parseInt($(window).width()/2);
			var winHeight=parseInt($(window).height()/2.2);
			var left=winWidth-marginLeft;
			var top=winHeight-marginTop;
			$('.webox').css({left:left,top:top});
			$('#'+option['locked']).mousedown(function(e){
				if(e.which){
					m=true;
					_x=e.pageX-parseInt($('.webox').css('left'));
					_y=e.pageY-parseInt($('.webox').css('top'));
				}
				}).dblclick(function(){
					if(allscreen){
						$('.webox').css({height:height,width:width});
						$('#inside').height(height);
						$('.w_iframe').height(height-30);
						$('.webox').css({left:left,top:top});
						allscreen = false;
					}else{
						allscreen=true;
						var screenHeight = $(window).height();
						var screenWidth = $(window).width();$
						('.webox').css({'width':screenWidth-18,'height':screenHeight-18,'top':'0px','left':'0px'});
						$('#inside').height(screenHeight-20);
						$('.w_iframe').height(screenHeight-50);
					}
				});
			}).mousemove(function(e){
				if(m && !allscreen){
					var x=e.pageX-_x;
					var y=e.pageY-_y;
					$('.webox').css({left:x});
					$('.webox').css({top:y});
				}
			}).mouseup(function(){
				m=false;
			});
			$(window).resize(function(){
				if(allscreen){
					var screenHeight = $(window).height();
					var screenWidth = $(window).width();
					$('.webox').css({'width':screenWidth-18,'height':screenHeight-18,'top':'0px','left':'0px'});
					$('#inside').height(screenHeight-20);
					$('.w_iframe').height(screenHeight-50);
				}
			});
	}
});
我弹出的DIV也是在同一个页面里啊 为什么没有办法调用keyup方法呢? 调试根本就没执行keyup方法 是不是html: $("#pingxie").html()写的有问题呢。大家帮我看看吧
wzb0712 2013-11-19
  • 打赏
  • 举报
回复
引用 25 楼 DT4261541 的回复:
成功了
<script type="text/javascript">
    
    $(document).ready(function () {
       
        $('#inside').click(function () {
            $.webox({
                height: 188,
                width: 400,
                bgvisibel: true,
                title: '内嵌弹出层调用',
                html: $("#pingxie").html()
            });
        });

        

    })
    function upperCase(obj) {
        var aaa = $("#spell").attr("title");
        var bbb = obj.value;
        if (aaa == bbb) {
            $(".div1").text("输入正确");


        }
        else {

            $(".div1").text("错误");

        }
    }
    </script>
</head>
<body>
<a  href="javascript:void(0);" id="inside" ><strong>单词拼写</strong></a>
<div id="div2"></div>
<div id="pingxie" style="display:none;">
 <div>
<input id="spell" title="123" name="spell" class="input wide" type="text"  onkeyup="upperCase(this)"/>
<div  class="div1"></div>

</div>
</div>
</body>
</html>
我通过id给div1赋值,$("#div1").text("...");赋值不上去,后来我试着按照wzb0712说的 把id换成class,居然成功了,虽然成功了但还是不知道为什么
id是唯一的,一个页面不能同时出现多个相同的id
DT4261541 2013-11-19
  • 打赏
  • 举报
回复
成功了
<script type="text/javascript">

$(document).ready(function () {

$('#inside').click(function () {
$.webox({
height: 188,
width: 400,
bgvisibel: true,
title: '内嵌弹出层调用',
html: $("#pingxie").html()
});
});



})
function upperCase(obj) {
var aaa = $("#spell").attr("title");
var bbb = obj.value;
if (aaa == bbb) {
$(".div1").text("输入正确");


}
else {

$(".div1").text("错误");

}
}
</script>
</head>
<body>
<a href="javascript:void(0);" id="inside" ><strong>单词拼写</strong></a>
<div id="div2"></div>
<div id="pingxie" style="display:none;">
<div>
<input id="spell" title="123" name="spell" class="input wide" type="text" onkeyup="upperCase(this)"/>
<div class="div1"></div>

</div>
</div>
</body>
</html>

我通过id给div1赋值,$("#div1").text("...");赋值不上去,后来我试着按照wzb0712说的 把id换成class,居然成功了,虽然成功了但还是不知道为什么
打字员 2013-11-19
  • 打赏
  • 举报
回复
小問題引出大問題...
wzb0712 2013-11-19
  • 打赏
  • 举报
回复
引用 22 楼 DT4261541 的回复:
改完直接成这样子
不行的话,你就等到把键盘事件加到

 $('#inside').click(function () {
            $.webox({
                height: 188,
                width: 400,
                bgvisibel: true,
                title: '内嵌弹出层调用',
                html: $("#pingxie").html()
            });
            //将键盘事件放到这里试下
           $(".spell").keyup(function(){
                //code
            })

        });
    
DT4261541 2013-11-19
  • 打赏
  • 举报
回复
引用 21 楼 wzb0712 的回复:

<script type="text/javascript" src="{config.templateskin}/js/jquery-webox.js"></script>
<script type="text/javascript">

$(document).ready(function () {

$('#inside').click(function () {
$.webox({
height: 188,
width: 400,
bgvisibel: true,
title: '内嵌弹出层调用',
html: $("#pingxie").html()
});
});


$("#spell").keyup(function () {

var aaa = $("#spell").attr("title");
var bbb = $("#spell").attr("value");
if (aaa == bbb) {
alert("相同");
}
else {
alert("不同");
}
});
})
</script>
</head>
<body>
<a href="javascript:void(0);" id="inside" ><strong>单词拼写</strong></a>
<div id="pingxie" style="display:none;">
<div>
<input id="spell" title="123" name="spell" class="input wide" type="text" />
</div>
</div>
</body>

将你的input标签的id换成class,
$('#inside').click(function () {
$.webox({
height: 188,
width: 400,
bgvisibel: true,
title: '内嵌弹出层调用',
html: $("#pingxie").html()
});
});这个调用里面的html后面改为:$("#pingxie").clone();

这个键盘事件#改为.就可以了
$("#spell").keyup(function () {

var aaa = $("#spell").attr("title");
var bbb = $("#spell").attr("value");
if (aaa == bbb) {
alert("相同");
}
else {
alert("不同");
}
});


改完直接成这样子
疯狂熊猫人 2013-11-18
  • 打赏
  • 举报
回复
使用浏览器调试看看。还有,把完整页面代码贴出来,你这样就俩段代码看不出问题在哪里,因为你写的js没有语法错误
DT4261541 2013-11-18
  • 打赏
  • 举报
回复
引用 9 楼 u011559804 的回复:
[quote=引用 7 楼 DT4261541 的回复:] [quote=引用 5 楼 u011559804 的回复:] [quote=引用 3 楼 DT4261541 的回复:] [quote=引用 1 楼 jsynzzp 的回复:] 试试在键盘的按下或放开事件里进行值得对比。
引用 2 楼 u011559804 的回复:
input 绑定一个keyup事件 每次输入都判断
 $("#spell").keyup(function () {
            
            var aaa = $("#spell").attr("title");
            var bbb = $("#spell").attr("value");
            if (aaa == bbb) {
                alert("相同");
            }
            else {
                alert("不同");
            }
        });
<div>
<input id="spell" title="" name="spell" class="input wide" type="text" />
</div>
一点反应都没有 我是用户点击图片我用jquery弹出上面的层 然后用户输入我在对比[/quote] 有效果啊 你在输入框中输入看看 title先设置个值[/quote] 你看看我6楼的代码 点击单词拼写弹出pingxie层 用户在pingxie里的文本框输入值我调用keyup判断 title赋了值也没用 试过了[/quote] 貌似你这个弹出层 是另一个页面了 你把事件绑定的代码放在弹出层里看看[/quote] 不行啊 放在弹出层里连jquery代码都不显示了
sliwey 2013-11-18
  • 打赏
  • 举报
回复
引用 7 楼 DT4261541 的回复:
[quote=引用 5 楼 u011559804 的回复:] [quote=引用 3 楼 DT4261541 的回复:] [quote=引用 1 楼 jsynzzp 的回复:] 试试在键盘的按下或放开事件里进行值得对比。
引用 2 楼 u011559804 的回复:
input 绑定一个keyup事件 每次输入都判断
 $("#spell").keyup(function () {
            
            var aaa = $("#spell").attr("title");
            var bbb = $("#spell").attr("value");
            if (aaa == bbb) {
                alert("相同");
            }
            else {
                alert("不同");
            }
        });
<div>
<input id="spell" title="" name="spell" class="input wide" type="text" />
</div>
一点反应都没有 我是用户点击图片我用jquery弹出上面的层 然后用户输入我在对比[/quote] 有效果啊 你在输入框中输入看看 title先设置个值[/quote] 你看看我6楼的代码 点击单词拼写弹出pingxie层 用户在pingxie里的文本框输入值我调用keyup判断 title赋了值也没用 试过了[/quote] 貌似你这个弹出层 是另一个页面了 你把事件绑定的代码放在弹出层里看看
DT4261541 2013-11-18
  • 打赏
  • 举报
回复
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  
  $("#spell").keyup(function(){
            var aaa = $("#spell").attr("title");
            var bbb = $("#spell").attr("value");
            if (aaa == bbb) {
                alert("相同");
            }
            else {
                alert("不同");
            }
  });
});
</script>
</head>
<body>
Enter your name: <input id="spell" title="123" name="spell" class="input wide" type="text" />
<p>当发生 keydown 和 keyup 事件时,输入域会改变颜色。请试着在其中输入内容。</p>
</body>
</html>
这样子就不会有问题
DT4261541 2013-11-18
  • 打赏
  • 举报
回复
引用 5 楼 u011559804 的回复:
[quote=引用 3 楼 DT4261541 的回复:] [quote=引用 1 楼 jsynzzp 的回复:] 试试在键盘的按下或放开事件里进行值得对比。
引用 2 楼 u011559804 的回复:
input 绑定一个keyup事件 每次输入都判断
 $("#spell").keyup(function () {
            
            var aaa = $("#spell").attr("title");
            var bbb = $("#spell").attr("value");
            if (aaa == bbb) {
                alert("相同");
            }
            else {
                alert("不同");
            }
        });
<div>
<input id="spell" title="" name="spell" class="input wide" type="text" />
</div>
一点反应都没有 我是用户点击图片我用jquery弹出上面的层 然后用户输入我在对比[/quote] 有效果啊 你在输入框中输入看看 title先设置个值[/quote] 你看看我6楼的代码 点击单词拼写弹出pingxie层 用户在pingxie里的文本框输入值我调用keyup判断 title赋了值也没用 试过了
加载更多回复(6)

87,991

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧