使用 javascript onclick 方法隐藏 SharePoint Web 部件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19226720/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hide SharePoint web part using javascript onclick method
提问by OQpls
i need a little bit of help, I am trying to use JavaScript embedded in a SharePoint Content editor web part to hide specific web parts as the items are clicked, however it does not seem to work can anyone give me any hints/ideas?
我需要一点帮助,我正在尝试使用嵌入在 SharePoint 内容编辑器 Web 部件中的 JavaScript 来在单击项目时隐藏特定的 Web 部件,但是它似乎不起作用任何人都可以给我任何提示/想法吗?
<script type="text/javascript">
function hidepart()
var hlf = document.getElementById("MSOZoneCell_WebPartWPQ3");
MSOZoneCell_WebPartWPQ3.style.display="none";
}
</script>
enter code here
<a id="myLink" href="#" onclick="hidepart();return false;">Test</a>
回答by Daniel Ward
<script type="text/javascript">
function hidepart() {
var hlf = document.getElementById("MSOZoneCell_WebPartWPQ3");
hlf.style.display="none";
}
</script>
enter code here
在这里输入代码
<a id="myLink" href="#" onclick="hidepart();return false;">Test</a>
you misspelled function and you were not using the hlf variable correctly. This should do it
您拼错了函数,并且没有正确使用 hlf 变量。这应该做
ok fixed you were missing a opening bracket too
好的修复你也缺少一个左括号
回答by Jinxed
You could use the following code :
您可以使用以下代码:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script language="JavaScript">
function hidepart()
{
$('#MSOZoneCell_WebPartWPQ3').hide();
}
</script>
enter code here
<a id="myLink" href="#" onclick="hidepart();return false;">Test</a>
回答by OQpls
I've managed to get it working like this, thank you harshini, your version also seems to work and looks a lot nicer.
我已经设法让它像这样工作,谢谢harrini,你的版本似乎也可以工作并且看起来好多了。
<script type="text/javascript">
function hidepart1() {
document.getElementById("MSOZoneCell_WebPartWPQ5").style.display = "none";}
</script>
<a id="myLink" href="#" onclick="hidepart1();return false;">Test</a>
Thanks guys for helping me out thought I should share this with you, maybe someone else needs this
谢谢你们帮我想我应该和你分享这个,也许其他人需要这个