Computer >> Máy Tính >  >> Lập trình >> Javascript

Làm cách nào để đặt kiểu phông chữ là bình thường, nghiêng hay xiên với JavaScript?


Để đặt kiểu phông chữ, hãy sử dụng fontStyle bất động sản. Bạn có thể thử chạy đoạn mã sau để đặt kiểu phông chữ thành bình thường, nghiêng hoặc xiên bằng JavaScript -

Ví dụ

<!DOCTYPE html>
<html>
   <body>
      <h1>Heading 1</h1>
      <p id="myID">
         This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text.
         This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text.
      </p>
      <button type="button" onclick="display()">Set Font Family and Style</button>
      <script>
         function display() {
            document.getElementById("myID").style.fontFamily = "verdana,sans-serif";
            document.getElementById("myID").style.fontStyle = "italic";
         }
      </script>
   </body>
</html>