简体   繁体   English

当他已经有信息时,如何使用 javascript 检查共享点列表是否包含特定单词

[英]How can I use javascript to check if a sharepoint list contains a specific word, when he is already have information

on my site I have list with column.在我的网站上,我有列列表。 One like "Status"(Choice column. Drop down menu) and when user change this column on Finished need alert him.一个喜欢“状态”(选择列。下拉菜单),当用户在完成时更改此列时需要提醒他。

HTML code of list and JQuery code (Past on Script Editor on WepPart)列表的 HTML 代码和 JQuery 代码(过去在 WepPart 上的脚本编辑器中)

 $(document).ready(function(){ $(".ms-formbody").blur(function() { var Text = $(this).val(); if (Text == "Finished") { alert("Alert"); } }); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <tr> <td width="113" class="ms-formlabel" nowrap="true" valign="top"> <span class="ms-h3 ms-standardheader" id="Status"> <nobr>Status <span title="This is a required field." class="ms-accentText"> *</span> </nobr> </span> </td> <td width="350" class="ms-formbody" valign="top"> <!-- FieldName="Status" FieldInternalName="Status" FieldType="SPFieldChoice" --> <span dir="none"> <select title="Status Required Field" class="ms-RadioText" id="Status_30b2ab26-c1c0-48fd-b190-854b32fe67ca_$DropDownChoice"> <option value="Planned">Planned</option> <option value="Development">Development</option> <option value="Executing">Executing</option> <option selected="selected" value="Finished">Finished</option> <option value="Cancelled">Cancelled</option> </select> <br> </span> <span class="ms-metadata">Choice</span> </td> </tr>

Ok, a few issues here:好的,这里有几个问题:

1) you're selecting completely the wrong element in the jQuery. 1) 您在 jQuery 中选择了完全错误的元素。 Currently it will match a <td element, but that doesn't have any change or blur events, and it doesn't have a value either.目前它将匹配<td元素,但它没有任何更改或模糊事件,也没有值。 You need to get hold of the dropdownlist in order to detect when it's changed.您需要掌握下拉列表以检测何时更改。 Given the HTML below, you can use the ms-RadioText class which the <select has got.给定下面的 HTML,您可以使用<select获得的ms-RadioText类。

2) "blur" is the wrong event to handle - this will only occur if the user moves the focus away from the dropdown after they selected a value. 2)“模糊”是错误的处理事件 - 只有当用户在选择一个值后将焦点从下拉列表中移开时才会发生这种情况。 You can't rely on this actually happening.你不能指望这实际发生。 "change" is the correct event. “变化”是正确的事件。

3) Your exact requirement for what should occur when the select changes is unclear and appears (from the comments) to have changed since the question was posted, so I'm going to give an example where it simply reports the newly selected value in all scenarios. 3)您对选择更改时应该发生什么的确切要求不清楚并且(从评论中)自问题发布以来已经发生变化,所以我将举一个例子,它只是简单地报告新选择的值场景。 If you want to do something more specific than that, you can easily add an if statement or whatever you need.如果您想做比这更具体的事情,您可以轻松添加if语句或您需要的任何内容。

Demo:演示:

 $(document).ready(function(){ $(".ms-RadioText").change(function() { var Text = $(this).val(); alert(Text); }); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <tr> <td width="113" class="ms-formlabel" nowrap="true" valign="top"> <span class="ms-h3 ms-standardheader" id="Status"> <nobr>Status <span title="This is a required field." class="ms-accentText"> *</span> </nobr> </span> </td> <td width="350" class="ms-formbody" valign="top"> <!-- FieldName="Status" FieldInternalName="Status" FieldType="SPFieldChoice" --> <span dir="none"> <select title="Status Required Field" class="ms-RadioText" id="Status_30b2ab26-c1c0-48fd-b190-854b32fe67ca_$DropDownChoice"> <option value="Planned">Planned</option> <option value="Development">Development</option> <option value="Executing">Executing</option> <option selected="selected" value="Finished">Finished</option> <option value="Cancelled">Cancelled</option> </select> <br> </span> <span class="ms-metadata">Choice</span> </td> </tr>

Use the code below to achieve it.使用下面的代码来实现它。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $("select[title='Status Required Field']").change(function(){
        if($(this).val()=="Finished"){
            alert("Alert");
        }
    });
});
</script>

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当文本框文本更改或添加时,如何使用javascript检查共享点文本字段是否包含特定单词? - How can I use javascript to check if a sharepoint textfield contains a specific word, when the textbox text changes or get added? 如何检查 javascript 数组是否已包含特定数组 - How can I check if javascript array already contains a specific array 我如何检查单击了哪个p以及他使用javascript包含了哪些innerhtml - how can I check which p was clicked and what innerhtml he contains with javascript Javascript:如何在数组上使用splice()移动特定单词? - Javascript: How can I use splice() on an array to move a specific word? 如何检查名称是否已在此列表中? - How can I check if a name is already in this list? 如何检查我的DOM是否已包含ID的元素? - How can i check if my DOM already contains an element by id? 如何检查字符串是否包含 JavaScript 中的短语或单词,但还要确保该单词不在另一个单词中? - How can I check if a string contains a phrase or word in JavaScript, but also make sure that the word isn't within another? JScript:如何检查字符串是否包含特定单词? - JScript: how to check if a string contains a specific word? Javascript:如何检查 URL 是否包含单词 - Javascript: How to check if URL contains a word 如何使用sharepoint2010中的javascript检查列表是否包含所需的行? - How to check if list contains needed rows using javascript in sharepoint2010?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM