0
我有基本的JavaScript代碼,需要告訴'我'或'ly'中5個結尾有多少個名字。我有代碼告訴有多少包含'ly'或'i',只是在最後。如何搜索以特定字符串結尾的單詞?
<script type="text/javascript">
var names = new Array(5);
var name;
function start_user_prompt() {
for(i=0;i<5;i++) {
name = prompt('Enter name '+(i+1));
names[i] = name;
}
e_names(names);
}
function e_names(names) {
var name_count = 0;
for(var i in names) {
// this needs to be changed to search it correctly
if((names[i].search(/ie/) > 0) || names[i].search(/y/) > 0) {
name_count++;
}
}
document.write('The number of special names is : '+name_count);
}
</script>
它也與* ff *一起使用嗎? – 2011-02-11 05:08:10