var p1=document.getElementById("p1");和p1.style.fontSize=ti;两个在不同的function方法中,前面一个为什么可以使用后面一个的参数。
js可以直接通过id获取dom对象的,不过不建议直接用id获取,最好是按照第一种方法
var p1=document.getElementById("p1");
这句话的意思,找到id是p1的标签对象,赋值给变量p1,修改成这样好理解些
var p1_obj=document.getElementById("p1");
至于引用
p1_obj.style.fontSize=12;
如果要在方法中引用的话,可以把p1_obj定义为全局来使用
var p1_obj=document.getElementById("p1");
function tt(){
p1_obj.style.fontSize=12;
}