Thuộc tính ‘src’ trong một nghi thức là ruta hacia một kho lưu trữ bên ngoài hoặc định kỳ mà bạn muốn mở một tài liệu HTML.
Ví dụ, nếu bạn tuvieses đề xuất kho lưu trữ cá nhân hóa JavaScript sẽ tạo ‘script.js’ và yêu cầu tổng hợp chức năng của trang HTML, thì hãy tổng hợp các phương pháp sau:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Ejemplo de atributo de script Src</title>
</head>
<body>
<script src="https://www.freecodecamp.org/espanol/news/como-enlazar-a-un-documento-javascript-en-html/./script.js"></script>
</body>
</html>
Điều này cho phép một tập tin lưu trữ ‘script.js’ mà bạn đang ở trong một thư mục lưu trữ .html sai. También puedes enlazar otros directorios usando ‘..’ en la ruta del archivo.
<script src="https://www.freecodecamp.org/espanol/news/public/js/script.js"></script>
Đây là một nơi mới đến của đạo diễn, trở thành một đạo diễn ‘công khai’, trở thành một đạo diễn ‘js’ và cả một kho lưu trữ ‘script.js’.
También có thể sử dụng thuộc tính ‘src’ để mở tệp lưu trữ “.js” bên ngoài alojados por un tercero. Esto se usa si no quieres descargar una copy local del archive. Solo ten en cuenta que siel enlace cambia or siel access de red está caído, el archive externo que estás enlazando no funcionar.
Đây là một ví dụ về một kho lưu trữ jQuery.
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
Traducido del artículo Liên kết JavaScript với HTML bằng tập lệnh src Thuộc tính