Javascript函数在IE中不起作用,但在Firefox中起作用 $(文档).ready(函数(){ showHome(); }); 函数findTemplate(){ var selectedIndustry=$(“#industrySelected option:selected”).text(); var selectedTemplate=$(“#templateCode”).val(); $.ajax({ 类型:“post”, url:“/\u layouts/TBSharePointProject/SharePointTestService.asmx/redirectUserToAppropriateTemplate”, contentType:“application/x-www-form-urlencoded”, 数据类型:“xml”, 数据:{行业:selectedIndustry,模板代码:selectedTemplate,检查表:'}, 成功:功能(结果){ xmlStr=xmlToString(结果); xml=removeFirstAndLastLine(xmlStr) myJsonObject=xml2json.parser(xml); //警报(myJsonObject.eccn[0].eccnno); $(“#surveyScreen”).empty(); 对于(变量i=0;i 0){ 返回newtext.substring(0,newtext.lastIndexOf(“\n”); }否则{ 返回新文本; } } 函数showHome(){ $(“#surveyScreen”).empty(); $(“#调查屏幕”)。附加(“
您有保存的检查表吗?”); $(“#调查屏幕”)。附加(“提交代码:”); $(“#调查屏幕”)。追加(“Javascript函数在IE中不起作用,但在Firefox中起作用 $(文档).ready(函数(){ showHome(); }); 函数findTemplate(){ var selectedIndustry=$(“#industrySelected option:selected”).text(); var selectedTemplate=$(“#templateCode”).val(); $.ajax({ 类型:“post”, url:“/\u layouts/TBSharePointProject/SharePointTestService.asmx/redirectUserToAppropriateTemplate”, contentType:“application/x-www-form-urlencoded”, 数据类型:“xml”, 数据:{行业:selectedIndustry,模板代码:selectedTemplate,检查表:'}, 成功:功能(结果){ xmlStr=xmlToString(结果); xml=removeFirstAndLastLine(xmlStr) myJsonObject=xml2json.parser(xml); //警报(myJsonObject.eccn[0].eccnno); $(“#surveyScreen”).empty(); 对于(变量i=0;i 0){ 返回newtext.substring(0,newtext.lastIndexOf(“\n”); }否则{ 返回新文本; } } 函数showHome(){ $(“#surveyScreen”).empty(); $(“#调查屏幕”)。附加(“,javascript,jquery,internet-explorer,Javascript,Jquery,Internet Explorer,您有保存的检查表吗?”); $(“#调查屏幕”)。附加(“提交代码:”); $(“#调查屏幕”)。追加(“”); $(“#调查屏幕”)。追加(“行业””; $(“#surveyScreen”)。附加(“”+ “计算机与网络”+ “生物技术”+ “工业”); $(“#调查屏幕”)。附加(“或”); $(“#调查屏幕”)。附加(“模板代码:”); $(“#调查屏幕”)。追加(“”); } 有人能给我解释一下为什么这个函数调用在Firefox中有效而在IE中无效,以及需要做些什么才能在IE中有效 所
”); $(“#调查屏幕”)。追加(“行业””; $(“#surveyScreen”)。附加(“”+ “计算机与网络”+ “生物技术”+ “工业”); $(“#调查屏幕”)。附加(“
或”); $(“#调查屏幕”)。附加(“模板代码:”); $(“#调查屏幕”)。追加(“
”); } 有人能给我解释一下为什么这个函数调用在Firefox中有效而在IE中无效,以及需要做些什么才能在IE中有效
所以我更新了帖子,展示了我的更多代码。有些代码被遗漏了……有些则不重要IE在重复ID时会更加挑剔。 ID(当然)应该是唯一的,但firefox只是抓住了第一个ID并继续。 IE忽略访问复制ID的尝试
你不能发布你的HTML,但这是我首先要看的方向。IE在复制ID时更挑剔。 ID(当然)应该是唯一的,但firefox只是抓住了第一个ID并继续。 IE忽略访问复制ID的尝试
你不能发布你的HTML,但这是我首先要看的方向。在调用这行代码之前,确保你没有在任何地方丢失分号。我发现,丢失分号(或任何其他错误)将导致IE在错误点停止工作,但它仍然在FF中工作 你的代码在IE 9中运行良好
$(“#调查屏幕”)。追加(“
”);
在调用这行代码之前,请确保您没有在任何地方漏掉分号。我发现漏掉的分号(或任何其他错误)将导致IE在出现错误的地方停止工作,但仍能在FF中工作
你的代码在IE 9中运行良好
$(“#调查屏幕”)。追加(“
”);
请添加一些标记。它在我的IE中起作用。什么样的元素是surveyScreen
?@未定义它不是元素,它是元素的id。Survey screen是一个div我怀疑它与问题有关,但您不需要onXXX
属性中的javascript:
。请添加一些标记。它是在我的IE中工作什么类型的元素是surveyScreen
?@未定义它不是元素,它是元素的id。Survey screen是一个div我怀疑它与问题有关,但您不需要onXXX
属性中的javascript:
。
<script type="text/javascript">
$(document).ready(function () {
showHome();
});
function findTemplate() {
var selectedIndustry = $("#industrySelected option:selected").text();
var selectedTemplate =$("#templateCode").val();
$.ajax({
type: "post",
url: "/_layouts/TBSharePointProject/SharePointTestService.asmx/redirectUserToAppropriateTemplate",
contentType: "application/x-www-form-urlencoded",
dataType: "xml",
data: { industry: selectedIndustry, templateCode: selectedTemplate, checkList: "" },
success: function (result) {
xmlStr = xmlToString(result);
xml = removeFirstAndLastLine(xmlStr)
myJsonObject = xml2json.parser(xml);
//alert(myJsonObject.eccn[0].eccnno);
$("#surveyScreen").empty();
for(var i = 0; i <= myJsonObject.eccn.length; i++) {
$("#surveyScreen").append("<p><input id='" + myJsonObject.eccn[i].guid + "' type='checkbox' checked ='checked'>" + myJsonObject.eccn[i].eccnno + ": " + myJsonObject.eccn[i].title + "</input></p>");
}
$("#surveyScreen").append("<br/><input type='button' id='goHome' value='Back' onclick =\"javascript: showHome();\"/>");
},
error: function (result) {
alert('error occured');
},
async: true
});
}
//Converst xmlString to String
function xmlToString(xmlObj) {
if (navigator.appName == "Netscape") {
return (new XMLSerializer()).serializeToString(xmlObj);
}
if (navigator.appName == "Microsoft Internet Explorer") {
return xmlObj.xml;
}
}
function removeFirstAndLastLine(xmlStr) {
// break the textblock into an array of lines
var lines = xmlStr.split('\n');
// remove one line, starting at the first position
lines.splice(0, 2);
// join the array back into a single string
var newtext = lines.join('\n');
//Removes the last line
if (newtext.lastIndexOf("\n") > 0) {
return newtext.substring(0, newtext.lastIndexOf("\n"));
} else {
return newtext;
}
}
function showHome() {
$("#surveyScreen").empty();
$("#surveyScreen").append("<p>Do you have a saved checklist?</p>");
$("#surveyScreen").append("<p>Submission Code:<input type='text' id='checkListCode'/> </p>");
$("#surveyScreen").append("<p><input type='button' id='getCheckList' value='Get Saved Checklist' onclick =\"javascript: findTemplate();\"/></p><br/><br/>");
$("#surveyScreen").append("<p>Industry</p>");
$("#surveyScreen").append("<select id='industrySelected'>"+
"<option>Computer & Networking</option>"+
"<option>Biotechnology</option>"+
"Industry</select>");
$("#surveyScreen").append("<br/>Or");
$("#surveyScreen").append("<p>Template Code:<input type='text' id='templateCode'/> </p>");
$("#surveyScreen").append("<p><input type='button' id='getTemplate' value='Next' onclick =\"javascript: findTemplate();\"/></p><br/><br/>");
}
</script>
<body>
<div id="surveyScreen">
</div>
</body>
$("#surveyScreen").append("<p><input type='button' id='getTemplate' value='Next' onclick=\"javascript: findTemplate();\"/></p><br/><br/>");