strike() 方法會讓字串顯示為帶有刪除線的文字,如同被包在 <strike> 標籤中一樣。它是 JavaScript 字串的一組早期 HTML 包装方法之一。
string.strike()
此方法沒有參數(標示為 NA)。
回傳帶有 <strike> 標籤的字串。
<html>
<head>
<title>JavaScript String strike() Method</title>
</head>
<body>
<script type="text/javascript">
var str = new String("Hello world");
alert(str.strike());
</script>
</body>
</html>
執行後會輸出:
<strike>Hello world</strike>
strike() 產生的 <strike> 標籤在現代 HTML 中已被視為過時,取而代之的是語意更明確的 <del>(表示刪除內容)與 <s>(表示不再準確或相關的內容)。若只是想加上刪除線的視覺效果,也可使用 CSS 的 text-decoration: line-through。選用語意化的標籤,能讓內容的意圖更清楚,也更符合現代網頁標準。