HTML DOM blockquote 本質上代表 HTML 元素 <blockquote>。與 <q> 標記不同,<blockquote> 元素不添加任何引號。我們可以在 blockquote 對象的幫助下創建和訪問 <blockquote> 屬性。
用法
以下是語法 -
創建塊引用對象 -
var x = document.createElement("BLOCKQUOTE");
示例
讓我們看一個 blockquote 對象的例子 -
<!DOCTYPE html>
<html>
<body>
<p>Click on the below button to create a blockquote object</p>
<button onclick="createBloc()">CREATE</button>
<script>
function createBloc() {
var x = document.createElement("BLOCKQUOTE");
var t = document.createTextNode("This is a random block quote.This is some sample text.");
x.setAttribute("cite", "http://www.examplesite.com");
x.setAttribute("id", "myQuote");
x.appendChild(t);
document.body.appendChild(x);
}
</script>
</body>
</html>
輸出
這將產生以下輸出 -
單擊創建 -
在上麵的例子中 -
首先,我們創建了一個按鈕 CREATE 來調用 createBloc() 函數。
<button onclick="createBloc()">CREATE</button>
函數 createBloc() 使用文檔對象的 createElement() 方法來創建 <blockquote> 元素。然後使用文檔對象的 createTextNode() 方法,我們創建了一個文本節點,其中包含一些文本。使用 setAttribute() 方法,我們向上麵創建的 <blockquote> 元素添加一些屬性,如 cite 和 id。然後使用 appendChild() 方法最終將該元素作為子元素附加到文檔正文中。
function createBloc() { var x = document.createElement("BLOCKQUOTE"); var t = document.createTextNode("This is a random block quote.This is some sample text."); x.setAttribute("cite", "http://www.examplesite.com"); x.setAttribute("id", "myQuote"); x.appendChild(t); document.body.appendChild(x); }
相關用法
- HTML DOM blockquote cite屬性用法及代碼示例
- HTML DOM blur()用法及代碼示例
- HTML DOM button用法及代碼示例
- HTML DOM Style overflowY屬性用法及代碼示例
- HTML DOM Document hidden屬性用法及代碼示例
- HTML DOM IFrame用法及代碼示例
- HTML DOM Textarea cols屬性用法及代碼示例
- HTML DOM Style pageBreakAfter屬性用法及代碼示例
- HTML DOM Base href屬性用法及代碼示例
- HTML DOM Pre用法及代碼示例
- HTML DOM Input Month用法及代碼示例
- HTML DOM Video canPlayType()用法及代碼示例
- HTML DOM Range deleteContents()用法及代碼示例
- HTML DOM console.dirxml()用法及代碼示例
- HTML DOM Style transition屬性用法及代碼示例
- HTML DOM Video volume屬性用法及代碼示例
- HTML DOM Input Range用法及代碼示例
- HTML DOM Style outlineOffset屬性用法及代碼示例
- HTML DOM Storage setItem()用法及代碼示例
- HTML DOM TableHeader用法及代碼示例
注:本文由純淨天空篩選整理自AmitDiwan大神的英文原創作品 HTML DOM blockquote object。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。