我不知道JavaScript,但我需要在公司内部网上使用SPServices。我需要在我的页面上将fieldNames写入一些div,我该怎么做?这是SPServices脚本:
<script type="text/javascript">
$( document ).ready(function(){
var thisUsersValues = $().SPServices.SPGetCurrentUser({
fieldNames: ["FirstName", "LastName", "Picture", "JobTitle", "WorkPhone", "WebSite",],
debug: false
});
</sript>
谢谢!
答案 0 :(得分:0)
var thisUsersValues = $().SPServices.SPGetCurrentUser({
fieldNames: ["FirstName", "LastName"],
debug: false
});
var name = thisUsersValues.FirstName + " " + thisUsersValues.LastName;
alert('Your name: ' + name);
我测试了这个,这是正确的用法。只需使用&#34;。&#34;语法,或者您可以使用thisUserValues['FirstName'];
和thisUserValues['LastName'];
来检索属性。
从那里,Cana发布的另一个答案是正确的:
var userDescription = "<div>" + name + "</div>";
var obj = $("#someObjId").append(userDescription);
答案 1 :(得分:0)
我知道这已经过时了(我是网站的新用户),但这是基于使用DOM的JavaScript的另一种选择。它将currentuser拉入变量并使用DOM插入div
。这也适用于输入字段。注意图片的.src。
<script type="text/javascript" language="javascript">
$(document).ready(function() {
var userdetails = $().SPServices.SPGetCurrentUser(
{
fieldNames: ["ID","EMail","UserName","FirstName","LastName","Picture","JobTitle","WorkPhone","Office"],
debug:false
});
document.getElementById('NameExample').innerHTML = (userdetails.FirstName + " " + userdetails.LastName);
document.getElementById('PhotoExample').src = (userdetails.Picture);
document.getElementById('EmailExample').innerHTML = (userdetails.EMail);
document.getElementById('TitleExample').innerHTML = (userdetails.JobTitle);
document.getElementById('OfficePhoneExample').innerHTML = ("Office" + " " + userdetails.WorkPhone);
document.getElementById('nameInputField').value = (userdetails.FirstName + " " + userdetails.LastName);
document.getElementById('emailInputField').value = (userdetails.EMail);
document.getElementById('OfficePhoneField').value = (userdetails.WorkPhone);
document.getElementById('titleInputField').value = (userdetails.JobTitle);
});
</script>
<div>
<span id="OfficePhoneExample"></span></br>
<span id="EmailExample"></span></br>
</div>
答案 2 :(得分:-1)
也许这可以帮到你:
var $userDescription = "<div>"+ thisUsersValues.toString() +"</div>";
$("#yourDivID").append($userDescription);