下面是我的代码,用于查明角色是否是元音。但是当我运行它时,它不会打印出真或假。
有人可以帮我看看我做错了什么吗?
var vowel = function(str) {
var matches = str.match(/[aeiou]/gi);
var count = matches ? matches.length : 0;
document.getElementByID('p').innerHTML = "'" + str + "contains" + count + "vowel(s)";
return false;
}
vowel(str);
<form>
<input type="text" name='t1'>
<input type='submit' value="SUBMIT" onclick='return vowel(this.form.t1.v'>
<div id="p"></div>
</form>
答案 0 :(得分:0)
而不是args2 = "Brahman"
尝试{
"this_id": "1001",
"name": "Animal Testing 1",
"species_type": "Cow",
"breed": "Brahman",
....
"herd": {
"id": 1,
"name": "High Production",
"description": null
}
},
{
"this_id": "1020",
"name": "Animal Testing 20",
"species_type": "Cow",
"breed": "Brahman",
....
"herd": {
"id": 4,
"name": "Bad Production",
"description": "Bad Production"
}
},
答案 1 :(得分:0)
您的代码存在一些问题。
1- getElementByID
应为getElementById
2-您没有关闭函数调用vowel(this.form.t1.v
3- t1.v
不是属性。您打算使用t1.value
var vowel = function(str) {
var matches = str.match(/[aeiou]/gi);
var count = matches ? matches.length : 0;
document.getElementById('p').innerHTML = "'" + str + "' contains " + count + " vowel(s)";
return false;
}
<form>
<input type="text" name="t1" />
<input type='submit' value="SUBMIT" onclick='return vowel(this.form.t1.value);' />
<div id="p"></div>
</form>