我有一个多次包含的php文件,所以没有一个ID,但是一次只能看到一个。我想要在这个PHP中显示一个div,具体取决于什么是键入的,即使它没有ID,我可以这样做吗?包括PHP文件:使用javascript显示div无ID
<script type="text/javascript">
function mobilecheck(inputted) {
var findstring = "07";
if (inputted.indexOf(findstring) > -1) {
//this works, I have tested with an 'alert'
document.getElementsByName("hiddenMobileDiv").style.display="block";
//show hidden div - this bit isn't working, I think it's because there's multiple divs with this name
}
}
</script>
<input type="tel" class="textbox" name="contactno" onkeypress="mobilecheck(this.value)">
<div name="hiddenMobileDiv" style="display:none">
<label class="label">What time can we contact you until?</label>
</div>
当你说“只有一个是可见的”,这是否意味着你是从DOM移除其他的人 - 或者只设置了显示为无?如果它们仍然存在于DOM上,则必须有额外的标准来确定要显示的正确标准。如果他们被删除,你可以使用joe_young的答案。 –