ไม่มีทางที่จะรักษา 0 นำหน้าใน JavaScript อย่างไรก็ตาม คุณสามารถถือว่า ID นี้เป็นสตริงและส่งผ่านเป็นอาร์กิวเมนต์ได้
ตัวอย่าง
คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อรักษา 0 นำหน้าโดยการทำให้เป็นสตริง -
<html>
<head>
<script>
function sayHello(name, age, id) {
document.write (name + " is " + age + " years old, with id = "+id);
}
</script>
</head>
<body>
<p>Click the following button to call the function</p>
<form>
<input type="button" onclick="sayHello('John', 26, '0678')"
value="Display Employee Info">
</form>
</body>
</html>