ECMAScript 之 获取 peoplePickerData 的ID 值 找了很久 请支持奥

<script type="text/javascript">

  function getXmlValue(xmlDocument, xpath) {

	var results = null;



	if (xmlDocument.evaluate) {

		results = xmlDocument.evaluate("/ArrayOfDictionaryEntry/DictionaryEntry[./Key = 'SPUserID']/Value", xmlDocument, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

		if (results.snapshotLength > 0) {

			return results.snapshotItem(0).textContent;

		}

	} else {

		results = xmlDocument.selectSingleNode(xpath);

		if (results != null) {

			return results.text;

		}

	}

	return null;

}

function getPeoplePickerDataDocument() {

   // alert($("[id$='txt_Name']").attr("id"));

   	       // var peoplePickerElement = document.getElementById('ctl00_m_g_f1062bbd_2a06_4cd8_8b12_eb31759d7693_txt_Name'),

      var peoplePickerElement =document.getElementById($("span[id$='_txt_Name']").attr("id")),

		peoplePickerDivs = peoplePickerElement.getElementsByTagName('div'),

		i,

		length = peoplePickerDivs.length,

		dataDiv = null,

		parser = null,

		dataDoc = null;

	for (i = 0; i < length; i = i + 1) {

		if (peoplePickerDivs[i].id != null) {

			if (peoplePickerDivs[i].id == 'divEntityData') {

				entityDataDiv = peoplePickerDivs[i];

				dataDiv = entityDataDiv.getElementsByTagName('div')[0];



				if (window.DOMParser) {

					parser = new DOMParser();

					dataDoc = parser.parseFromString(dataDiv.attributes["data"].value, "text/xml");

				} else {

					dataDoc = new ActiveXObject("Microsoft.XMLDOM");

					dataDoc.async = "false";

					dataDoc.loadXML(dataDiv.attributes["data"].value); 

				}

				return dataDoc;

			}

		}

	}

	return null;

}

</script>

var Name=$("div[id$='_txt_Name_upLevelDiv']").text();
         var peoplePickerData = getPeoplePickerDataDocument();
         var userId = getXmlValue(peoplePickerData, "/ArrayOfDictionaryEntry/DictionaryEntry[./Key = 'SPUserID']/Value"); 

 

peoplePickerData

你可能感兴趣的:(ECMAScript)