HTML 2_Menguji apakah string berisi karakter tertentu, dengan indexof()

<html>
<body>
<script type="text/javascript">
var str="W3CSchools is great!"
var pos=str.indexOf("School")
if (pos>=0)
{
document.write("School found at position: ")
document.write(pos + "<br />")
}
else
{
document.write("School not found!")
}
</script>
<p>This example tests if a string contains a specified word. If the word is
found it returns the position of the first character of the word in the original
string. Note: The first position in the string is 0!</p>
</body>
</html>
Category: 0 komentar

0 komentar:

Posting Komentar