main1.appendChild(createa("http://idcbgp.cn","慕課網(wǎng)")
<body>
<script type="text/javascript">
var main1 = document.body;
//創(chuàng)建鏈接
function createa(url,text)
{
??? var alink = document.createElement("a");
??? alink.setAttribute("href",url);
??? alink.innerHTML=text;
??? return alink;
?? ?
?? ?
}
// 調(diào)用函數(shù)創(chuàng)建鏈接
main1.appendChild(createa("http://idcbgp.cn","慕課網(wǎng)"));
</script>
</body>
加粗部分怎么解釋?createa是哪里來的?
2016-09-06
加粗部分是將創(chuàng)建的鏈接作為子節(jié)點(diǎn)添加到main1表示的body中,createa就是調(diào)用前定義的方法function create(url,text)
2016-08-31
你把加粗的部分拆開好理解點(diǎn)。拆成main1.appendChild(alink)和create("http://idcbgp.cn","慕課網(wǎng)")這兩部分。前面是運(yùn)用appendChild()來實(shí)現(xiàn)插入你前面定義的新節(jié)點(diǎn)而插入的位置就是main1。后面的create("http://idcbgp.cn","慕課網(wǎng)")對(duì)應(yīng)的是前面函數(shù)的參數(shù)createa(url,text)。里面的url,和text都是還沒有被定義的。后面加個(gè)create("http://idcbgp.cn","慕課網(wǎng)"),就對(duì)應(yīng)了url="http://idcbgp.cn",text="慕課網(wǎng)"。所以說里面的參數(shù)自己隨便定義,你給個(gè)百度鏈接什么的都可以的,這只是后面給值了.
2016-08-18
加粗部分的意思是在body里面插入運(yùn)行createa方法,createa是 ?function createa(url,text){}這個(gè)方法的方法名,createa("http://idcbgp.cn","慕課網(wǎng)")? 對(duì)應(yīng) createa(url,text)。