本文主要介紹了jQuery實現獲取h1-h6標題元素值的方法,涉及$(":header")選擇器操作h1-h6元素及事件響應相關技巧,需要的朋友可以參考下,希望能幫助到大家。
1、問題背景:
查找到h1-h6,并遍歷它們,打印出內容
2、實現代碼:
查找標題$(function(){
//查找h1-h6
$(":header").each(function(){
$(this).click(function(event){
console.info(event.target.innerText);
console.log(event.currentTarget.innerHTML);
});
});
});
Hello H1
Hello H2
Hello H3
Hello H4
Hello H5
Hello H6
3、運行效果圖:
相關推薦: