【发布时间】:2018-10-19 18:34:48
【问题描述】:
我在内容编辑器中创建了一个按钮,例如改变内容框的背景颜色。
按下按钮后,背景颜色从黑色变为白色。但是 Sharepoint 会自动刷新它并没有保存更改。有人对此有任何想法吗?它也发生在 IE 和 Chrome 中。
最好的问候,
安迪
<button onclick="changeCo()">Change Color</button>
<style>
#contentBox {
background-Color:black;
}
</style><script>
function changeCo(){
var elem = document.getElementById("contentBox");
var theCSSprop = window.getComputedStyle(elem,null).getPropertyValue("background-color");
if (theCSSprop == 'rgb(0, 0, 0)') {
document.getElementById('contentBox').style.backgroundColor = 'white';
}else{
document.getElementById('contentBox').style.backgroundColor = 'black';
}
}
</script>
【问题讨论】:
-
什么时候刷新?请记住,SharePoint 是一个基于服务器的应用程序,而客户端代码就是这样,客户端。要使客户端上的更改在页面刷新之间持续存在,您需要存储更改并重新应用它们。您可以使用 cookie 来做到这一点,但
localStorage更容易。 -
背景颜色发生变化,网站自行刷新。我忘了把 return false;在按钮之后:)
标签: javascript sharepoint sharepoint-designer