Javascript Javascript将共享点表单字段值获取到变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8559559/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 06:30:07  来源:igfitidea点击:

Javascript to get sharepoint form field value to a variable

javascript

提问by Sijo

I want to copy the content of a sharepoint form field to a variable using Javascript.

我想使用 Javascript 将共享点表单字段的内容复制到变量中。

Eg. I have a field named "Language" in my sharepoint edit form. Now I just want to get the value of that field to a varaible x.

例如。我的共享点编辑表单中有一个名为“语言”的字段。现在我只想将该字段的值设为变量 x。

Please help.

请帮忙。

BR

BR

回答by Athens Holloway

It depends on the type (e.g. user, lookup, multilookup, text, note, etc.) of field. I am using jQuery in my custom list forms and the name of the field for any given content type will be added to the id of the corresponding html control with the text 'Field' appended to it. However, like any typical asp.net control, the id of the html form control rendered to the client will reflect its control hierarchy so you have to account for that when searching for a field. anyhow, the following works for me if i need to reference fields in my custom forms. ** notice the +Field which implies that the name of the field is concatenated with 'Field'

这取决于字段的类型(例如用户、查找、多查找、文本、注释等)。我在我的自定义列表表单中使用 jQuery,并且任何给定内容类型的字段名称将添加到相应 html 控件的 id 中,并附加文本“字段”。但是,与任何典型的 asp.net 控件一样,呈现给客户端的 html 表单控件的 id 将反映其控件层次结构,因此您必须在搜索字段时考虑到这一点。无论如何,如果我需要引用自定义表单中的字段,以下内容对我有用。** 注意 +Field 这意味着该字段的名称与 'Field' 连接

var $titleField = $('input[id*=TitleField]');
var $lookupField = $('select[id*=Name_Of_Field+Field]')
var $multiLookUpCandidate = $('select[id*=Name_Of_Field+Field][id*=SelectCandidate]')
var $multiLookUpResult = $('select[id*=Name_Of_Field+Field][id*=SelectResult]')
var $note = $('textarea[id*=Name_Of_Field+Field]');

You can pick up on the trend by viewing source and seaching for your contenttype/sitecolumn field name. You will find it in an html form control id. use that information to learn how to reference other field types.

您可以通过查看源代码和搜索您的内容类型/站点栏字段名称来了解趋势。您将在 html 表单控件 ID 中找到它。使用该信息来了解如何引用其他字段类型。

回答by Manse

Without posting your code its very difficult to understand what you want to do.... to get a value from a form you can do the following :

如果不发布您的代码,很难理解您想要做什么......要从表单中获取值,您可以执行以下操作:

HTML

HTML

<form id="myform">
  <input id="myinput" type="text" value="something" />
</form>

JavaScript:

JavaScript:

var myinputval = document.getElementById("myinput").value;

myinputvalwould be "something" in this example

myinputval在这个例子中将是“某物”

Demo : http://jsfiddle.net/Qk6FZ/

演示:http: //jsfiddle.net/Qk6FZ/

回答by Jim Davis

This might help:

这可能有帮助:

http://depressedpress.com/2012/09/24/obtaining-a-javascript-reference-to-a-sharepoint-field/

http://depressedpress.com/2012/09/24/obtaining-a-javascript-reference-to-a-sharepoint-field/

Using that function you'd get the reference using something like:

使用该函数,您可以使用以下内容获取参考:

var LanguageFld = getFieldRef("Language");

Once you have the refernece it's easy to get the value:

一旦你有了参考,就很容易获得价值:

var CurValue = LanguageFld.value;

Hope this helps!

希望这可以帮助!