在html.begin的javascript中无法识别名称标记

在html.begin的javascript中无法识别名称标记,javascript,asp.net-mvc,html,razor,Javascript,Asp.net Mvc,Html,Razor,我这里有一些javascript <script type="text/javascript"> //Autocomplete variables var input = document.getElementById('location'); var searchform = document.getElementById('form1'); var place; 忽略蓝线,它应该可以正常工作。我在我的项目中复制了你的代码,无法复制。你是否碰巧使用了旧版本的IE?IE对i

我这里有一些javascript

<script type="text/javascript">
//Autocomplete variables
    var input = document.getElementById('location');
var searchform = document.getElementById('form1');
var place;

忽略蓝线,它应该可以正常工作。我在我的项目中复制了你的代码,无法复制。你是否碰巧使用了旧版本的IE?IE对id和名称属性匹配的表单元素有问题我正在使用Windows 8.1附带的任何版本,但我认为这不是IE的问题,而是razor语法的VS问题?当我交换掉我创建的两个版本的表单时,上面显示的一个工作正常,另一个中断。这与我的行为有关。当我用Results操作替换javascript:void0时,它可以工作。同意,但我只是想确保您理解,如果用户使用IE7,由于id和name属性具有相同的值,您的代码可能会失败。
<form action="javascript:void(0);" name="form1" id="form1">
<input type="text" name="location" class="textbox" id="location" value="" />
<input type="submit" value="Submit" class="submit" />
</form>
@using (Html.BeginForm("Results", "Home", FormMethod.Get, new { name = "form1", id = "form1" }))
{
    <p>
        @*@Html.TextBox("Location", null, new {id = "location"})*@
        <input type="text" name="location" id="location" value="" />
    </p>
    <p>
        <input class="btn btn-primary btn-lg" value='Submit' type="submit"/>
    </p>
}
var searchform = document.getElementById('form1');