首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Javascript函数在IE中不起作用,但在Firefox中起作用

Javascript函数在IE中不起作用,但在Firefox中起作用
EN

Stack Overflow用户
提问于 2013-02-23 00:12:42
回答 2查看 3.1K关注 0票数 0
代码语言: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>

有人能给我解释一下为什么这个函数调用可以在Firefox中工作而不能在IE中工作,以及需要做些什么才能在IE中工作。

所以我更新了这篇文章,以显示更多我的code..some片段被留下了,还有一些不重要

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-02-23 00:19:30

当涉及到重复ids时,IE要挑剔得多。ids (当然)应该是唯一的,但firefox只是抓取了第一个ids并继续。IE忽略访问复制ids的尝试。

你不需要张贴你的HTML,但这是我首先要看的方向。

票数 3
EN

Stack Overflow用户

发布于 2013-02-23 00:25:45

在调用这行代码之前,请确保没有遗漏分号。我发现缺少分号(或任何其他错误)会导致IE在错误的地方停止工作,但它仍然可以在FF中工作。

您的代码在IE 9 http://jsfiddle.net/eL2nU/中运行良好

代码语言:javascript
复制
$("#surveyScreen").append("<p><input type='button' id='getTemplate' value='Next' onclick=\"javascript: findTemplate();\"/></p><br/><br/>");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15028466

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档