我有一些JavaScript,它有两个部分,因为我在代码中标记,当我添加第二部分我的部分脚本自动检测到其他地方关闭该部分,如果我不添加该部分它很好我很抱歉,如果它凌乱
@section Scripts{
<script type="text/javascript">
var myResult;
$(document).keypress(function (e) {
var mydata;
if (e.which == 13) {
var drp = document.getElementById('autocomplete').value;
$.ajax({
dataType: "json",
type: "POST",
url: "@Url.Action("turbineDeviceDetail","AdminTool")",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ "turbine": drp, }),
success: function (result) {
myResult = result;
var flg = "s";
$.ajax({
dataType: "json",
type: "POST",
url: "@Url.Action("producersDevice","AdminTool")",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ "flg": flg, }),
success: function (data) {
mydata = data;
}
})
var flg_dvType = "s";
$.ajax({
dataType: "json",
type: "POST",
url: "@Url.Action("deviceTypeList","AdminTool")",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ "flg": flg_dvType, }),
success: function (data) {
mydata_deviceType = data;
}
});
//
////
function ProductNameDropDownEditor(container, options) {
$('<input name="Producer" data-type="string"\">')
.appendTo(container)
.kendoDropDownList({
valuePrimitive: true,
dataSource: mydata,
dataTextField: "Text",
dataValueField: "Text",
});
}
function deviceTypesList(container, options) {
$('<input name="DeviceType" data-type="string" \">')
.appendTo(container)
.kendoDropDownList({
dataSource: mydata_deviceType,
dataTextField: "Text",
dataValueField: "Text",
//dataValueField: "ProductName",
});
}
}
})
}
});
//This Part Is For The AUTOCOMPLETE textbox
$(document).ready(function () {
var value = document.getElementById('autocomplete').value;
$.ajax({
dataType: "json",
type: "POST",
url: "@Url.Action("List_Turbine","AdminTool")",
contentType: "application/json; charset=utf-8",
//data: JSON.stringify({ "name": value ,}),
data: {},
success: function (result) {
$("#autocomplete").kendoAutoComplete({
dataSource: result,
dataTextField: "Text",
// filter: "contains"
});
}
})
});
$(document).ready(function () {
dataSource = new kendo.data.DataSource({
transport: {
read: function (options) {
options.success(myResult); // where data is the local data array
},
update: function (options) {
debugger;
$.ajax({
type: "POST",
url: "/Home/Update",
data: options.data.models[0],
dataType: "json",
success: function (data) {
options.success(data);
// alert("success");
},
error: function (data) {
options.error(data);
// alert("error");
},
});
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
//},
batch: true,
pageSize: 20,
schema: {
//data: employee,
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
firstName: { validation: { required: true } },
lastName: { validation: { required: true } },
//UnitPrice: { type: "number", validation: { required: true, min: 1} },
//Discontinued: { type: "boolean" },
//UnitsInStock: { type: "number", validation: { min: 0, required: true } }
}
}
}
});
$("#turbingrid").kendoGrid({
// debugger;
dataSource: result,
scrollable: false,
columns: [
{ field: 'DeviceIP', title: 'DeviceIP', width: '100px', id: 'DeviceIP' },
{ field: 'Producer', title: 'Producer', width: '80px', editor: ProductNameDropDownEditor, },
{ field: 'Model', title: 'Model', width: '120px' },
{ field: 'DeviceType', title: 'DeviceType', width: '100px', editor: deviceTypesList },
{ field: 'Description', title: 'Description', width: '100px' },
{ field: 'Username', title: 'Username', width: '120px' },
{ field: 'Password', title: 'Password', width: '100px' },
{ field: 'PublicIP', title: 'PublicIP', width: '120px' },
{ command: ["edit"], title: " ", width: "100px" }],
editable: "popup",
edit:
function () {
document.getElementsByName("DeviceIP")[0].disabled = true;
},
editable: "popup"
});
});
</script>
答案 0 :(得分:0)
首先排除错误:
一旦遇到错误,Javascript就不会继续执行执行线程。您的代码完全可能存在,但它尚未到达。
<强>故障排除:强>
如果我是你,我会使用开发者控制台(F12)验证我的错误是什么,如果我的脚本在那里,请检查实际的DOM。
从这里开始,您将有更好的基础来进行调试。
祝你好运
PS:也许如果您发现了错误,可以编辑您的帖子以包含它。
您的问题似乎是}
过早地关闭了@section
阻止。 如果您的代码不在DOM中,这是唯一的解释。
梳理您的代码并找到语法错误所在的位置。