$(..)位置选择器不是函数-Jquery位置选择器OnChanged事件出错
我在asp.net mvc中使用-在页面加载时,它在默认位置上指向正确,在浏览器控制台上不会生成错误,但当我将地图上的标记位置更改为其他位置时,它会给出错误$(..)。locationpicker不是一个函数 我在以下jquery行中出错-$(..)位置选择器不是函数-Jquery位置选择器OnChanged事件出错,jquery,asp.net-mvc,google-maps,jquery-plugins,error-handling,Jquery,Asp.net Mvc,Google Maps,Jquery Plugins,Error Handling,我在asp.net mvc中使用-在页面加载时,它在默认位置上指向正确,在浏览器控制台上不会生成错误,但当我将地图上的标记位置更改为其他位置时,它会给出错误$(..)。locationpicker不是一个函数 我在以下jquery行中出错- var addressComponents = $(this).locationpicker('map').location.addressComponents; HTML代码 <div class="form-group">
var addressComponents = $(this).locationpicker('map').location.addressComponents;
HTML代码
<div class="form-group">
<label class="control-label col-md-2">Country</label>
<div class="col-md-10">
@Html.DropDownList("Countries", null, "-- Select Country--", htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.State, "State", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("States", null, "-- Select State --", htmlAttributes: new { @class = "form-control" })
@*@Html.ValidationMessageFor(model => model.State, "", new { @class = "text-danger" })*@
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.City, "City", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("Cities", null, "-- Select City --", htmlAttributes: new { @class = "form-control" })
@*@Html.ValidationMessageFor(model => model.City, "", new { @class = "text-danger" })*@
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ZipCode, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ZipCode, new { htmlAttributes = new { @class = "form-control" } })
<input type="hidden" name="DataID" value="@ViewBag.BusinessID" />
@Html.ValidationMessageFor(model => model.ZipCode, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="col-md-6">
<div id="us2" style="width: 550px; height: 400px;"></div>
<div class="clearfix"> </div>
</div>
国家
@DropDownList(“Countries”,null,“--Select Country--”,htmlAttributes:new{@class=“form control”})
@LabelFor(model=>model.State,“State”,htmlAttributes:new{@class=“controllabel col-md-2”})
@DropDownList(“States”,null,“--Select State--”,htmlAttributes:new{@class=“form control”})
@*@Html.ValidationMessageFor(model=>model.State,“,new{@class=“text danger”})*@
@LabelFor(model=>model.City,“City”,htmlAttributes:new{@class=“controllabel col-md-2”})
@DropDownList(“Cities”,null,“--Select City--”,htmlAttributes:new{@class=“form control”})
@*@Html.ValidationMessageFor(model=>model.City,“,new{@class=“text danger”})*@
@LabelFor(model=>model.ZipCode,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.ZipCode,new{htmlAttributes=new{@class=“form control”}})
@Html.ValidationMessageFor(model=>model.ZipCode,“,new{@class=“text danger”})
Jquery代码-
<script src="~/assets/js/jquery.js" type="text/javascript"></script>
<script type="text/javascript" src='http://maps.google.com/maps/api/js?sensor=false&libraries=places'></script>
<script src="~/assets/js/locationpicker.jquery.js"></script>
<script>
$('#us2').locationpicker({
location: { latitude: 46.15242437752303, longitude: 2.7470703125 },
radius: 100,
inputBinding: {
latitudeInput: $('#us2-lat'),
longitudeInput: $('#us2-lon'),
radiusInput: $('#us2-radius'),
locationNameInput: $('#us2-address')
}, onchanged: function (currentLocation, radius, isMarkerDropped) {
var addressComponents = $(this).locationpicker('map').location.addressComponents;
// updateControls(addressComponents);
console.log(addressComponents);
console.log(addressComponents.length);
for (var key in addressComponents) {
if (addressComponents.hasOwnProperty(key)) {
//alert(key + " -> " + addressComponents[key]);
if (key == "postalCode") {
$('#ZipCode').val(addressComponents[key]);
}
if (key == "country") {
$('#country').val(addressComponents[key]);
}
if (key == "stateOrProvince") {
$('#States').val(addressComponents[key]);
}
if (key == "city") {
$('#Cities').val(addressComponents[key]);
}
}
}
}, oninitialized: function (component) {
var addressComponents = $(component).locationpicker('map').location.addressComponents;
// updateControls(addressComponents);
},
enableAutocomplete: true
});
</script>
$('#us2')。位置选择器({
地点:{纬度:46.15242437752303,经度:2.74703125},
半径:100,
输入绑定:{
纬度输入:$('us2 lat'),
纵向输入:$('us2 lon'),
半径输入:$(“#us2半径”),
locationNameInput:$(“#us2地址”)
},onchanged:function(当前位置、半径、isMarkerDroped){
var addressComponents=$(this).locationpicker('map').location.addressComponents;
//UpdateControl(addressComponents);
控制台日志(addressComponents);
console.log(addressComponents.length);
for(地址组件中的var键){
if(addressComponents.hasOwnProperty(键)){
//警报(键+“->”+地址组件[键];
如果(键==“后代码”){
$('#ZipCode').val(addressComponents[key]);
}
如果(关键字=“国家”){
$(#country').val(addressComponents[key]);
}
如果(键==“州或省”){
$('#States').val(addressComponents[key]);
}
如果(键==“城市”){
$(#Cities').val(addressComponents[key]);
}
}
}
},oninitialized:功能(组件){
var addressComponents=$(component).locationpicker('map').location.addressComponents;
//UpdateControl(addressComponents);
},
enableAutocomplete:正确
});
将代码包装在$(document).ready(函数)中。@AnoopJoshi确定让我来try@AnoopJoshi我试过了,但把它放在$(文档)下之后.ready map已停止显示,因此它已删除。它在页面加载时未出错。它仅在发生更改事件后才会出错occurs@Steve-工作小提琴-我在代码中没有看到任何问题。您确定jquery文件加载正确吗?