HTML id Attribute
ဥပမာ
JavaScript ဖြင့် စာသားကို စီမံခန့်ခွဲရန် id attribute ကိုသုံးပါ-
<html>
<body>
<h1 id="myHeader">Hello World!</h1>
<button onclick="displayResult()">Change text</button>
<script>
function displayResult()
{
document.getElementById("myHeader").innerHTML = "Have a nice day!";
}
</script>
</body>
</html>
အောက်တွင် နောက်ထပ် "စမ်းသုံးကြည့်ပါ" ဥပမာများ။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
ရည်ညွှန်းချက် သည် id
HTML ဒြပ်စင်တစ်ခုအတွက် သီးသန့် ID ကို သတ်မှတ်ပေးသည် (တန်ဖိုးသည် HTML စာရွက်စာတမ်းအတွင်း သီးသန့်ဖြစ်ရမည်)။
ရည်ညွှန်းချက် သည် id
စတိုင်စာရွက်ရှိ စတိုင်တစ်ခုအား ညွှန်ပြရန် အများဆုံးဖြစ်ပြီး၊ တိကျသော ID ဖြင့် ဒြပ်စင်ကို ကိုင်တွယ်ရန် JavaScript (HTML DOM မှတဆင့်) ဖြင့် အသုံးပြုသည်။
Browser ပံ့ပိုးမှု
Attribute | |||||
---|---|---|---|---|---|
id | Yes | Yes | Yes | Yes | Yes |
အထားအသို
<element id="id">
ရည်ညွှန်းတန်ဖိုးများ
Value | Description |
---|---|
id | Specifies a unique id for the element.
Naming rules:
|
နောက်ထပ် ဥပမာများ
ဥပမာ ၁
စာမျက်နှာတစ်ခုအတွင်း သတ်မှတ်ထားသော id တစ်ခုနှင့် ချိတ်ဆက်ရန် id attribute ကိုသုံးပါ-
<html>
<body>
<h2><a id="top">Some heading</a></h2>
<p>Lots of text....</p>
<p>Lots of text....</p>
<p>Lots of text....</p>
<a href="#top">Go to top</a>
</body>
</html>
ဥပမာ ၂
CSS ဖြင့် စာသားပုံစံပြုလုပ်ရန် id attribute ကိုသုံးပါ-
<html>
<head>
<style>
#myHeader {
color: red;
text-align: center;
}
</style>
</head>
<body>
<h1 id="myHeader">W3Schools is the best!</h1>
</body>
</html>
ဆက်စပ်စာမျက်နှာများ
HTML သင်ခန်းစာ- HTML ID
HTML သင်ခန်းစာ- HTML အရည်အချင်းများ
CSS သင်ခန်းစာ- CSS Syntax
CSS ရည်ညွှန်းချက်- CSS #id ရွေးချယ်မှု
HTML DOM ရည်ညွှန်းချက်- HTML DOM getElementById() နည်းလမ်း
HTML DOM ရည်ညွှန်းချက်- HTML DOM id ပိုင်ဆိုင်မှု
HTML DOM ရည်ညွှန်း- HTML DOM စတိုင် Object