error:jquery不能输出我想要的内容
2014-08-19 10:57
155 查看
1、想通过each函数来遍历所有的input的value值。代码如下:
但是html显示的是空的内容,很奇怪。。于是,我就怀疑可能是each函数中的if语句有问题,然后我就注释掉if语句,换成一个简单的显示语句,如下:
3、和正确的代码一比较,才发现attr("check")是不对的,正确的应该是attr("checked")最终正确的应该是
function SelectAll(o){ var html = ''; if( $(o).find("#select_all2").attr("checked") ){ $(o).parent("p").siblings(".boxright_all").find("input").attr("checked",true); $(o).parent("p").siblings(".boxright_all").find("input").each(function(){ if($(this).attr("check") == true||$(this).attr("check") == "checked") { html += $(this).val(); alert("新的value"); } }); }else{ $(o).parent("p").siblings(".boxright_all").find("input").removeAttr('checked'); } alert(html); }
但是html显示的是空的内容,很奇怪。。于是,我就怀疑可能是each函数中的if语句有问题,然后我就注释掉if语句,换成一个简单的显示语句,如下:
function SelectAll(o){ var html = ''; if( $(o).find("#select_all2").attr("checked") ){ $(o).parent("p").siblings(".boxright_all").find("input").attr("checked",true); $(o).parent("p").siblings(".boxright_all").find("input").each(function(){ alert($(this).val()); /* if($(this).attr("check") == true||$(this).attr("check") == "checked") { html += $(this).val(); alert("新的value"); } */ }); }else{ $(o).parent("p").siblings(".boxright_all").find("input").removeAttr('checked'); } //alert(html); }结果能显示出内容。看来结果很明显,是each中的if语句出问题了。
3、和正确的代码一比较,才发现attr("check")是不对的,正确的应该是attr("checked")最终正确的应该是
function SelectAll(o){ var html = ''; if( $(o).find("#select_all2").attr("checked") ){ $(o).parent("p").siblings(".boxright_all").find("input").attr("checked",true); $(o).parent("p").siblings(".boxright_all").find("input").each(function(){ if($(this).attr("checked") == true||$(this).attr("checked") == "checked") { html += $(this).val(); html += ";"; } }); }else{ $(o).parent("p").siblings(".boxright_all").find("input").removeAttr('checked'); } alert(html); }
相关文章推荐
- error:用printf或者是cout输出指针时,不能输出指针所指的内容!
- 使用jQuery.get(url,[data],[callback])不能获取返回的页面XML内容
- Jquery 获得table的行数,并输出单元格的内容
- 探讨php中error_log函数输出内容的原子性问题
- mybatis generator,报错XML Parser Error on line 1:前言中不能有内容,
- linux下printf函数为什么不加\n就不能输出相关的内容 ?
- 在c#中将dataset输出成xml内容的xls文件,解决其它输出不能在excel中显示“001”的前导0的问题
- JQuery_ select2的搜索框不能输入搜索内容
- 解决discuz与jquery不兼容问题——下拉列表不能用(Uncaught TypeError: Cannot set property 'position' of undefined)
- error:使用rebuild编译链接dll文件和exe文件,结果改变产生dll的源文件的内容,输出结果都没有改变
- jquery、js获取table,遍历输出tr中各个td的内容。
- jQuery在异步请求数据返回后,调用$("selector").html(data.content);之后因为一些特殊字符或者',"不能显示内容的问题解决办法
- jquery each控制checkbox有关内容(table tr)的显示或隐藏(jquery 按条件隐藏显示已输出内容)
- DbgView 显示OutputDebugString 输出内容 不能显示问题总结
- DbgView不能显示OutputDebugString的输出内容
- error:system("type d:\\1.txt");不能查看文件的内容
- DbgView 显示OutputDebugString输出内容 不能显示问题总结
- 从键盘输入一个字符串存入数组a中,再将数组a的内容复制到数组b中并 输出(不能调用strcpy函数)?
- thinkphp 3.2.1 控制器使用show方法不能得到输出内容
- PHPEXCEL 不能输出中文内容,只显示空白