将原始代码复制到test.html文件并在IE10中打开后,如你所说它不起作用。我发现脚本中有换行符会导致它变得无效 - 尤其是字符串中的字符串文字 alert(" ") 的。我在过去发现,从手册,pdf和帮助文件中复制可能包含不需要的字符,因此请使用优秀的代码编辑器仔细检查。它还有助于设置缩进,以便您可以轻松查看代码中发生的情况。
alert(" ")
<html> <head> <title> Data View Javascript Demo Page </title> <script type="text/javascript"> var xmlDoc; var xmlhttp; var DATAVIEW_URI = "/user/system/dataviews/Sample.xml"; var DATAVIEW_NAMESPACE = "http://www.rockwellautomation.com/technologies/data_access/data_views/1.0/"; var DATATYPES_NAMESPACE = "http://www.rockwellautomation.com/technologies/data_access/data_types/1.0/"; var ARR_ACTIVEX = ["MSXML4.DOMDocument", "MSXML3.DOMDocument", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XmlDom"]; var STR_ACTIVEX = ""; var isIE = navigator.userAgent.toLowerCase().indexOf("msie") > -1; if (isIE) { var bFound = false; for (var i=0; i < ARR_ACTIVEX.length && !bFound; i++) { try { var objXML = new ActiveXObject(ARR_ACTIVEX[i]); STR_ACTIVEX = ARR_ACTIVEX[i]; bFound = true } catch (objException) {} } if (!bFound) { /* No DOM found, so throw a message and go back */ alert("Creating/editing a data view requires Internet Explorer 5.5 or greater with XML support. Please upgrade your browser or load the appropriate patches to support XML."); history.go(-1); } } else { /* Not IE, so throw a message and go back */ alert("Creating/editing a data view requires Internet Explorer 5.5 or greater with XML support. Please upgrade your browser or load the appropriate patches to support XML."); history.go(-1); } xmlDoc = new ActiveXObject(STR_ACTIVEX) xmlDoc.async = false; xmlDoc.setProperty("SelectionLanguage", "XPath"); if (STR_ACTIVEX.indexOf(".DOMDocument") != -1) { xmlhttp = new ActiveXObject(STR_ACTIVEX.substring(0, STR_ACTIVEX.indexOf(".DOMDocument")) + ".XMLHTTP"); } else { alert("Creating/editing a data view requires Internet Explorer 5.5 or greater with XML support. Please upgrade your browser or load the appropriate patches to support XML."); history.go(-1); } function refresh_value() { xmlDoc.load(DATAVIEW_URI); xmlDoc.setProperty("SelectionNamespaces", "xmlns:dv='" + DATAVIEW_NAMESPACE + "'"); document.getElementById("tagvalue").value = xmlDoc.selectSingleNode("/dv:view/dv:tag[@name='TEST']/dv:value").childNodes[0].nodeValue; } function update_value() { xmlDoc.selectSingleNode("/dv:view/dv:tag[@name='TEST']/dv:value").childNodes[0].nodeValue = document.getElementById("tagvalue").value; xmlhttp.Open("POST", DATAVIEW_URI, false); xmlhttp.Send(xmlDoc); refresh_value(); } </script> </head> <body onLoad="refresh_value();"> TEST value is <input type="text" name="tagvalue" id="tagvalue" /><br/> <input type="button" onClick="refresh_value();" value="Refresh"/> <input type="button" onClick="update_value();" value="Update"/> </body> </html>
现在你的下一个障碍是让浏览器运行该代码,因为IE10可能不支持ActiveX。这是一个不同的问题,但......