楼主:
red0whale (red whale)
2017-02-17 16:32:02像jquery,原先如果是这样:
$("#div").css({"background-color":"#00FF00","color":"#FF0000"});
$("#div").animate({"width":"200px","height":"100px"},1000);
$("#div").on("click",function(){
console.log("clicked");
});
要简化并提升它的执行效率的话就可以使用“方法链串”:(可以省去不必要的重复分析
目标元素)
$("#div").css({"background-color":"#00FF00","color":"#FF0000"}).animate({"widt
h":"200px","height":"100px"},1000).on("click",function(){
console.log("clicked");
});
那如果是传统的javascript呢?
document.getElementById("div").style.backgroundColor = "#00FF00";
document.getElementById("div").style.color = "#FF0000";
....
是不是只要将“document.getElementById("div")”用一个变量取代就可以了
还是要用其他方法?
谢谢