<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瀏覽器的東西。JavaScript函數在IE瀏覽器不工作,但在Firefox
所以我更新了帖子,以顯示更多的我code..some件冷落......和其他一些不重要
請添加一些您的標記。它的作品在我的IE – 2013-02-22 16:14:16
「surveyScreen」是什麼類型的元素? – undefined 2013-02-22 16:14:22
@undefined它不是一個元素,它是一個元素的id。 – 2013-02-22 16:15:08