我的javascript中没有从html.beginform中识别出名称标签

时间:2015-01-23 01:07:16

标签: javascript asp.net-mvc html5 razor

我在这里有一些javascript

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

我在html中创建了一个表格,看起来像这样,一切正常

<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>

但是当我更改表单以使用像这样的HTML.BeginForm

@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>
}

下面的javascript无法识别form1名称,并且其下方有一条蓝线,上面显示一条消息,其中显示&#34;无法解析ID&#39; form1&#39;&#34;

var searchform = document.getElementById('form1');

0 个答案:

没有答案