我有一些适用于IE的代码,但不适用于FireFox。加载页面时,将调用PlantingGPSAction函数,但是单击“删除”按钮时,不会发生任何事情。在FireFox中使用调试器工具时,确实看到以下错误:XML解析错误:未找到根元素,未定义事件(引用onclick和PlantingGPSAction)。
以下代码:
<div id="div-plantingGPS">
<a href="#" onclick="PlantingGPSAction(event, 'Add')">Add New GPS</a>
<div class="row">
<span class="col-md-3 col-xs-12">
<label>County</label>
</span>
<span class="col-md-3 col-xs-12">
<label>Latitude</label>
</span>
<span class="col-md-3 col-xs-12">
<label>Longitude</label>
</span>
<span class="col-md-3 col-xs-12">
<label>Remove</label>
</span>
</div>
@foreach (LicensePIIHGPSCoor GSPCoor in Model)
{
if (String.IsNullOrEmpty(GSPCoor.TransCode))
{
GSPCoor.TransCode = AgRSys.Classes.Entity.TRANSCODESTATUS_UPDATE;
}
<div class="row PlantingAreaGPS" style="margin-bottom:10px;" data-GPSID="@GSPCoor.GPSID" data-transcode="@GSPCoor.TransCode">
<!--County-->
<span class="col-md-3 col-xs-12">
@*<label>County</label>*@
@Html.DropDownList("PlantCountySelect",new SelectList((SelectList)ViewBag.CountyList,"value", "text", GSPCoor.IntendedPlantCounty), new { @class = "form-control county-select-list", @value = @GSPCoor.IntendedPlantCounty })
</span>
<!--Latitude-->
<span class="col-md-3 col-xs-12">
@*<label>Latitude</label>*@
<input class="form-control Latitude" type="text" value="@GSPCoor.Latitude" />
</span>
<!--Longitude-->
<span class="col-md-3 col-xs-12">
@*<label>Longitude</label>*@
<input class="form-control Longitude" type="text" value="@GSPCoor.Longitude" />
</span>
<!--Remove-->
<span class="col-md-3 col-xs-12">
@*<label>Remove</label>*@
<button type="button" class="btn btn-danger btn-sm" onclick="PlantingGPSAction(event, 'Remove');">Remove</button>
</span>
</div>
}
<script>
var PlantingGPSAction = function (e, Action) {
if (Action === "Add") {
var Plantingdiv = $('#div-plantingGPS');
var NewDiv = $('<div>', { "class":"row PlantingAreaGPS", style:"margin-bottom:10px;", "data-GPSID": "", "data-transcode": "@AgRSys.Classes.Entity.TRANSCODESTATUS_ADD" });
//Create select for type
var NewSelectPlanting = $('<select>', { "class": "form-control county-select-list" });
@foreach (SelectListItem county in ViewBag.CountyList as SelectList)
{
<text>var option = $('<option>', { "value": '@county.Value', 'text': '@county.Text' });</text>
<text>$(NewSelectPlanting).append(option);</text>
}
// append the select to the span, and ten the span to the div
var NewSpanCounty = $('<span>', { "class": "col-md-3 col-xs-12" });
$(NewSpanCounty).append(NewSelectPlanting);
$(NewDiv).append(NewSpanCounty);
// Create new Latitude
var NewSpanLatitude = $('<span>', { "class": "col-md-3 col-xs-12" });
var inputLatitude = $('<input>', { "class": "Latitude form-control", "value": "" });
$(NewSpanLatitude).append(inputLatitude);
$(NewDiv).append(NewSpanLatitude);
// Create new Longitude
var NewSpanLongitude = $('<span>', { "class": "col-md-3 col-xs-12" });
var inputLongitude = $('<input>', { "class": "Longitude form-control", "value": "" });
$(NewSpanLongitude).append(inputLongitude);
$(NewDiv).append(NewSpanLongitude);
//Create remove button
var rmbtn = $('<button>', { "type": "button", "class": "btn btn-danger btn-sm", text: "Remove" });
rmbtn.click(function () { PlantingGPSAction(event, "Remove"); })
var NewSpanBtn = $('<span>', { "class": "col-md-3 col-xs-12" });
$(NewSpanBtn).append(rmbtn);
$(NewDiv).append(NewSpanBtn);
$(NewDiv).append($('<br />'));
$(Plantingdiv).append(NewDiv);
}
if (Action === 'Remove') {
var div = $(event.target).closest('div.row.PlantingAreaGPS');
if ($(div).attr('data-transcode') == '@AgRSys.Classes.Entity.TRANSCODESTATUS_ADD') {
$(div).remove();
}
if ($(div).attr('data-transcode') == '@AgRSys.Classes.Entity.TRANSCODESTATUS_UPDATE') {
$(div).attr('data-transcode', '@AgRSys.Classes.Entity.TRANSCODESTATUS_REMOVE');
$(div).children().addClass('strikeout');
$(event.target).text('Removed');
}
}
}
</script>