有如下代码:<html><head><script type="text/javascript" src="/jquery/jquery.js"></script><script type="text/javascript">$(document).ready(function(){$("button").click(function(){$("p").append(function(m){return "<b>This p element has index " + m + "</b>";});});});</script></head><body><h1>This is a heading</h1><p>This is a paragraph.</p><p>This is another paragraph.</p><button>在每个 p 元素的结尾添加内容</button></body></html>点击一次按钮后的结果是:This is a headingThis is a paragraph.This p element has index 0This is another paragraph.This p element has index 1问:那个参数m是如何根据不同的匹配元素自增的呢?PS:如果我给$("p").append(function(m)写两个参数,即$("p").append(function(m,n),下边也相应的改成return "<b>This p element has index " + (m+n) + "</b>";会怎么样呢?求达人讲解原理~~~结果中的0和1是怎么来的呢?
添加回答
举报
0/150
提交
取消