html中的代码:
<input type="text" name="fileName" id="fileName" class="file_input_textbox" readonly="readonly" />
<div class="file_input_div">
<input type="button" value="Search files" class="file_input_button" />
<input type="file" class="file_input_hidden" onchange="javascript: document.getElementsByName('fileName')[0].value = this.value" />
</div>
它工作正常。但如果我会这样写:
<input runat="server" type="text" name="fileName" id="fileName" class="file_input_textbox" readonly="readonly" />
<div class="file_input_div">
<input type="button" value="Search files" class="file_input_button" />
<input type="file" class="file_input_hidden" onchange="javascript: document.getElementsByName('fileName')[0].value = this.value" />
</div>
它不起作用,错误:document.getElementsByName(...).0' is null or not an object