0
<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 中工作。

所以我更新了帖子以显示更多我的代码..有些部分被遗漏了......而其他一些则不重要

4

2 回答 2

3

IE 在重复 id 方面更加挑剔。ids(当然)应该是唯一的,但 Firefox 只是抓住第一个并继续。IE 会忽略访问欺骗 ID 的尝试。

您不会发布您的 HTML,但这是我首先要看的方向。

于 2013-02-22T16:19:29.807 回答
0

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

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

$("#surveyScreen").append("<p><input type='button' id='getTemplate' value='Next' onclick=\"javascript: findTemplate();\"/></p><br/><br/>");
于 2013-02-22T16:25:44.653 回答