我試圖在單擊按鈕時在頁面上顯示「事實」。我將事實列表設置爲一個帶有循環的字符串數組,應該如下所示通過循環。試圖讓一個字符串數組按照順序打印出來,然後單擊一個按鈕
var textArray = [
"<strong>Fact 1:</strong> Sign language is the fourth most used language in the US.",
"<strong>Fact 2:</strong> Deaf History Month is observed from March 13th to April 15th every year.",
"<strong>Fact 3:</strong> There are hundreds of sign language dialects in use around the world. Each culture has developed its own form of sign language to be compatible with the language spoken in that country.",
"<strong>Fact 4:</strong> A form of ASL has been used in the U.S. for over two hundred years.",
"<strong>Fact 5:</strong> In the United States, many people with hearing impairments communicate by using American Sign Language, also known as ASL. ASL combines hand signs, gestures, and facial expressions to create words and sentences. As many as 500,000 people in the U.S. communicate using ASL. Not all ASL users are hearing impaired. Some are family members, friends, or teachers of people with hearing impairments.",
"<strong>Fact 6:</strong> You might think that modern-day ASL originated in England, but it did not. It came from France. England has its own version of sign language that is very different from ASL. An American who only knows ASL will have a hard time communicating with someone from England who only knows Modern British Sign Language. But a person using ASL has a good chance of being able to communicate with a person using French Sign Language - even if they don't speak French!",
"<strong>Fact 7:</strong> People with hearing impairments have been using signed languages for a very long time. In the 18th century in France, some people did not think children with hearing impairments should go to school. They thought that since they could not speak or hear, they would be unable to learn. A man with a hearing impairment named Pierre Desloges believed these people were wrong. He wrote a book that described the signed language used by people with hearing impairments in Paris. This book helped to change the minds of many people. Soon there were schools in France for children with hearing impairments. ",
"<strong>Fact 8:</strong> Ludvig van Beethoven was a German composer and pianist. He started going deaf at the age of 28 and by age 49 he could no longer hear. He continued to get worse but went on composing music. Beethoven died in 1857 when he was 57 years-old.",
"<strong>Fact 9:</strong> There are hundreds of sign language dialects in use around the world. Each culture has developed its own form of sign language to be compatible with the language spoken in that country.",
"<strong>Fact 10:</strong> Babies can communicate physically 6-8 months prior to communicate verbally."
];
function factClick(){
var arrayLength = textArray.length;
for (var i = 0; i < arrayLength; i++) {
document.getElementById("factID").innerHTML = textArray[i];
}
}
而且它應該打印出被點擊我的頁面(http://thecodingninja.com/muslim/facts.php)上的按鈕時。
下面
<script src="facts.js"></script>
<center>
<p id="factID" style="color:white;"> test <p>
<button onclick="factClick()">Change Text</button>
</center>
代碼爲什麼不工作?
如果更容易,您可以在jQuery中給出答案。
控制檯中的任何錯誤? – Rayon
不,不存在 – MuslimTwin
任何特定的原因PHP被標記在這個問題上?你發佈的所有代碼似乎都是客戶端的東西。 –