【发布时间】:2020-05-06 05:43:42
【问题描述】:
我是 sharepoint 的新手。
我已经创建了一个列表。在新项目窗口中,我想根据下拉选择值显示或隐藏字段。我知道它可以使用 jquery 来完成,如下面的链接所示。但我不知道在哪里放置代码。
谢谢
【问题讨论】:
标签: javascript sharepoint-2010 show-hide
我是 sharepoint 的新手。
我已经创建了一个列表。在新项目窗口中,我想根据下拉选择值显示或隐藏字段。我知道它可以使用 jquery 来完成,如下面的链接所示。但我不知道在哪里放置代码。
谢谢
【问题讨论】:
标签: javascript sharepoint-2010 show-hide
步骤:
代码
<script>
$(document).ready(function ()
{ // Get a the choice field
var choiceField = SPUtility.GetSPField('Job Title');
// Hide the target fields in form load
SPUtility.GetSPField('Other Title').Hide();
// create a function to show or hide a field based on the selected choice Field value
var ShowHideField = function() {
var selectedFieldValue = choiceField.GetValue();
// Hide the 'Other Title' field if the selected value is 'Other'
if(selectedFieldValue != 'Other') {
SPUtility.GetSPField('Other Title').Hide(); }
else { SPUtility.GetSPField('Other Title').Show(); } };
// attach the function to choice field
$(choiceField.Dropdown).on('change', ShowHideField); });
</script>
[输出]
注意:将
Job Title替换为您选择的字段名称,将Other Title替换为您需要显示或隐藏的字段 选择字段选择。
更多详情,请查看
【讨论】:
然后转到您的列表主页
List Tools>List>Form Web Parts>Default New Form
然后单击Add a Web Part 并在Categories 下选择Media and Content > Content Editor。点击Add将其添加到页面。
在内容编辑器的左侧,您将看到一个箭头。单击它并选择Edit Web Part。在Content Link 下单击按钮打开Text Editor。添加您的 aspx 页面的 URL。
例如,如果页面存储在Site Assets 库中并称为newform.aspx,则url 为[url path to site assets]/SiteAssets/newform.aspx。转到存储脚本的位置并复制浏览器显示的链接:复制到/SiteAssets/ 或@ 987654333@ 另一个图书馆。然后附加脚本名称。您会注意到相对 URL 就足够了,它从 /sites/ 开始。
但是 newform.aspx 必须这样编辑:
<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
<SharePoint:ScriptLink Name="sp.ribbon.js" runat="server" OnDemand="true" Localizable="false" />
<SharePoint:ScriptLink Name="SP.js" runat="server" OnDemand="true" Localizable="false" />
<script type="text/javascript">
/*Your script here*/
/*examples*/
myFunction1()
{}
myFunction2()
{}
jQuery(document).ready(function ($)
{
ExecuteOrDelayUntilScriptLoaded(myFunction1, "sp.js"); //if the function operates on the form
ExecuteOrDelayUntilScriptLoaded(myFunction2, "sp.ribbon.js"); //if the function operates on the ribbon
});
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=windows-1252" http-equiv="Content-Type" />
<title>Page</title>
</head>
<body>
</body>
</html>
</asp:Content>
1。如果您想处理表单和/或功能区,请通过在页面顶部添加必要的标签来请求服务器加载 sp.js and sp.ribbon.js
2.您可以添加自定义html:否则删除
3.另存为.aspx
【讨论】:
Default New Form 时,您可以在一个框内看到Add a Web Part。点击它。