HTML里一个标签的属性值可以设为一个js变量吗

HTML里一个标签的属性值可以设为一个js变量吗

HTML里一个标签的属性值可以设为一个js变量吗

或许可以理解为js动态修改HTML标签的属性值

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <a id="aId" href="">动态设置跳转地址</a>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
       let a = document.getElementById("aId")
       a.setAttribute("href", "https://www.baidu.com/")
    </script>
</body>

</html>

你是想表达这个?

<div data-id="344"  class="div"></div>
<script>
$(".div").data(id)
</script>