Eolaire Eolaire
foghlamtha go córasachláithreán gréasáin a thógáilteicniúilSinsearachTá a fhios ag saineolaithe conas cláir JavaScript a úsáid go héasca.
Tá go leor cód JavaScript éasca le húsáid roinnte ag daoine eile ar an Idirlíon.
más féidir leatWordPressNuair a chuirfear cód JS leis an alt is cinnte go mbeidh an t-alt ildaite.
Conas cód JS a chur le hailt WordPress
Tá sé an-simplí cód JavaScript a chur le post WordPress.
Ar Aghaidh,Chen WeiliangRoinnfidh tú:Conas cód JavaScript a chur le postálacha WordPress?
De ghnáth bíonn 2 bhealach ann chun cód JS a chur leis:
- Cuir cód JS go díreach le postálacha WordPress
- Cuir glaoch ar chód JS in alt WordPress tar éis duit comhad JS a scríobh
1) Cuir cód JS go díreach leis an bpost WordPress
An chéad mhodh, JavaScript a scríobh go díreach sa phost WordPress.
Seo sampla de phriontáil an téacs "Hello World!" ▼
<script type="text/javascript">// <![CDATA[ document.write("Hello World!") // ]]></script>
Tá sé seo i bpost WordPress a thaispeánann “Hello World!” tar éis JavaScript ▼ a fhorghníomhú
2) Tar éis duit an comhad JS a scríobh, cuir glaoch ar an gcód JS san alt WordPress
Maidir leis an dara modh, scríobh an cód JavaScript chuig comhad ar leith.
Ansin sa phost WordPress nuair is gá an JavaScript a chur isteach, cuir glaoch ar an gcomhad JavaScript tríd an eagarthóir téacs WordPress.
Tá an sampla seo a leanas i bpost WordPress, ag priontáil téacs "Hello World" ▼
<script type="text/javascript" src="https://img.chenweiliang.com/javascript/hello.js">// <![CDATA[ // ]]></script>
Ábhar an chomhaid JavaScript hello.js ▼
document.write("Hello World");
Nuair a chuirtear cód JavaScript le post WordPress, léirítear na torthaí ▼
Glaonn WordPress ar chód JS le haghaidh dáta an lae inniu
Tá go leor cód JavaScript spraoiúil agus úsáideach ar an Idirlíon.
Anois tabhair sampla de conas iad a úsáid?
Priontáil dáta an lae inniu i bpoist WordPress.
Cuir an comhad JavaScript date.js seo a leanas isteach i do phostáil WordPress ▼
<script type="text/javascript" src="https://img.chenweiliang.com/javascript/date.js"></script> <script type="text/javascript">// <![CDATA[ // call function if required. // ]]></script>
Anseo thíos tá an t-ábhar JavaScript sa chomhad date.js ▼
var calendarDate = getCalendarDate(); document.write("Today is: " + calendarDate); function getCalendarDate() { var months = new Array(13); months[0] = "January"; months[1] = "February"; months[2] = "March"; months[3] = "April"; months[4] = "May"; months[5] = "June"; months[6] = "July"; months[7] = "August"; months[8] = "September"; months[9] = "October"; months[10] = "November"; months[11] = "December"; var now = new Date(); var monthnumber = now.getMonth(); var monthname = months[monthnumber]; var monthday = now.getDate(); var year = now.getYear(); if(year < 2000) { year = year + 1900; } var dateString = monthname + ' ' + monthday + ', ' + year; return dateString; } // function getCalendarDate()
Seo an toradh ar JavaScript a fhorghníomhú dáta an lae inniu i bpost WordPress ▼
Anseo thíos tá toradh an chomhaid JavaScript date.js a fhorghníomhaíodh san Airteagal seo ▼
注意 事项
Chun cód JS a chur isteach i bpostáil, ní mór duit an t-eagarthóir WordPress a athrú go mód téacs.
aird ar leith和之间不能有换行。
Má tá briseadh líne ann, déanfaidh WordPress é a phróiseáil go huathoibríoch mar mhír, agus cuirfidh sé clib p go huathoibríoch a fhágann go dteipeann ar an gcód script JS.
Tá níos mó altanna ar chód WordPress JavaScript anseo ▼
Tá súil agam Blag Chen Weiliang ( https://www.chenweiliang.com/ ) shared” Conas Cód JavaScript a Chur le Poist WordPress? , chun cabhrú leat.
Fáilte romhat nasc an ailt seo a roinnt:https://www.chenweiliang.com/cwl-1348.html
Fáilte chuig cainéal Telegram de bhlag Chen Weiliang chun na nuashonruithe is déanaí a fháil!
📚 Tá luach ollmhór sa treoir seo, 🌟 Seo deis annamh, ná caill é! ⏰⌛💨
Roinnigí agus más maith libh!
Is iad do chomhroinnt agus do thaitin ár spreagadh leanúnach!