一段代码,大神们给解释下

dayrenlar 2012-10-17 04:32:47
......省略一
target.find('input[dataExplain]').each(function () {
if ($(this).attr('type') == 'password') {
var pw = $(this);

var text = $('<input type="text"/>');
var attrs = ['id', 'name', 'style'];
for (var n in $(this)[0]) {
if (/^className$/.test(n)) {
text.attr(n, $(this).attr(n));
}
if (attrs.indexOf(n) >-1) {
var attrVal = $(this).attr(n);
if (attrVal != null && attrVal != '')
text.attr(n, attrVal);
}
}
text.val(pw.attr('dataExplain'));

谁给我解释下红色的那句
...全文
104 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
dayrenlar 2012-10-17
  • 打赏
  • 举报
回复
完全同意你的看法,不研究了,没意义,结贴,40分都给你得了
泡泡鱼_ 2012-10-17
  • 打赏
  • 举报
回复
不对呀,除非它有对数组定义一个indexOf扩展,否则应该是错的吧
类似于这样:
Array.prototype.indexOf=function(a){
return this.toString().indexOf(a);
};
alert(attrs.indexOf(n))

否则应该强制转换一下呀
attrs.toString().indexOf(n)
泡泡鱼_ 2012-10-17
  • 打赏
  • 举报
回复
var attrs = ['id', 'name', 'style'];
上面的attrs直接使用时,值为:id,name,style
dayrenlar 2012-10-17
  • 打赏
  • 举报
回复
no no no ,2楼的那位,这里的n其实是nextsibling
dayrenlar 2012-10-17
  • 打赏
  • 举报
回复
按理说数组根本就没有indexOf这方法呀,这是在肯德基网上订餐的网站中摘下来的,貌似在人家网站上不出错
wuqiong1314 2012-10-17
  • 打赏
  • 举报
回复
我猜:n0='id',n1= 'name',n2='style';indexOf():js函数判断字符串位置的

87,904

社区成员

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

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