如何使用 JavaScript 在 標籤中設定文字?


首先,設定 <strong> 元素 −

<strong id="strongDemo">Replace This strong tag</strong>

上述 id 屬性將用於使用 # 設定文字 −

$(document).ready(function(){
   $("#strongDemo").html("Actual value of 5+10 is 15.....");
});

示例

 即時演示

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initialscale=1.0">
<title>Document</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<strong id="strongDemo">Replace This strong tag</strong>
<script>
   $(document).ready(function(){
      $("#strongDemo").html("Actual value of 5+10 is 15.....");
   });
</script>
</body>
</html>

要執行以上程式,請儲存檔名“anyName.html(index.html)”,右鍵單擊該檔案。在 VS Code 編輯器中選擇“使用即時伺服器開啟”選項。

輸出

這會生成以下輸出 −

更新日期: 10-Sep-2020

881 次瀏覽

開啟您的職業

完成本課程將獲得認證

開始學習
廣告