简体   繁体   English

需要获取我单击按钮的行上的字段的值

[英]Need to get the value of a field on a row that I am clicking a button

I have a list view at the bottom of a SharePoint page (aspx) and each record is a contact that provides support. 我在SharePoint页面(aspx)的底部有一个列表视图,每个记录都是提供支持的联系人。 I have Name, Email address, and a button that should open an email and grab the email address that is next to it. 我有名称,电子邮件地址和一个按钮,该按钮应打开电子邮件并获取其旁边的电子邮件地址。 The button is added on the screen via js and is NOT part of the list view. 该按钮是通过js添加到屏幕上的,并且不是列表视图的一部分。 How does the button clicking function get that address that is just to the left of it? 按钮单击功能如何获得其左侧的地址?

I have been looking and looking. 我一直在寻找。

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {  
    addButtons();
});
function addButtons(){
     var $t = $('#js-listviewthead-WPQ2').next().next().find('tr');
    $t.each(function(){
        $(this).append("<input type='button' value='Help' id='btnSub' onclick='javascript:openMail();'>");
    });
}
function openMail(){
    var emailString = "mailto:";
    var emailID = getEmail('SharePointName');
//alert(emailID);

    emailString += emailID ;
    emailString += "?Subject=SharePoint Site Support - Site=";
    emailString += _spPageContextInfo.webServerRelativeUrl;;
    //alert(emailString);
    location.href=emailString;
}
function getEmail(title) {
    var userEmail = "Steve.@Wi.gov";
    return userEmail;
}
</script>

I want to take the email address and append it to the emailString to create the appropriate href. 我想获取电子邮件地址并将其附加到emailString上,以创建适当的href。

We can use the code below to achieve it, modify the "listTitle" in the code to make it works in one list view web part. 我们可以使用下面的代码来实现它,修改代码中的“ listTitle”以使其可以在一个列表视图Web部件中使用。

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {  
     addButtons();
});
function addButtons(){
    var listTitle="CustomList";
    $("table.ms-listviewtable[summary='"+listTitle+"']>tbody>tr").each(function(){
        $(this).append("<input type='button' value='Help' class='btnSub' onclick='javascript:openMail(this);'>");
    });
}
function openMail(btn){
    var emailString = "mailto:";
    var emailID = $(btn).prev("td").text();
    //alert(emailID);

    emailString += emailID ;
    emailString += "?Subject=SharePoint Site Support - Site=";
    emailString += _spPageContextInfo.webServerRelativeUrl;;
    //alert(emailString);
    location.href=emailString;
}
</script>

在此处输入图片说明

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

相关问题 第一次单击后,单选按钮不会更改值 - Radio button is not changing the value once I am clicking first time 如何通过单击DataTable的同一行上的“编辑”按钮获取Id值 - How to get Id value by clicking Edit button on the same row of DataTable 单击 Slack 应用程序上的按钮时如何获取字段值? - How to get the field value when clicking on a button on a Slack app? 如何从与我按下的按钮位于同一行的单元格中获取值 - How can I get the value from a cell which is in the same row as the button I am pressing 如何获得我在其中单击复选框的listview行的ID或引用? - How do I get the ID or reference of the listview row I am clicking a checkbox in? 通过单击按钮传递文本字段值 - Passing the text field value by clicking the button 文本字段不是通过单击按钮来读取值,而是直到我将值实际添加到文本字段中为止 - text field is not reading values by clicking button but until i add the value physically into text field 单击相应按钮如何连续获取文本? - how to get text in a row on clicking corresponding button? 我正在单击一个按钮,我想在该按钮上添加 class - I am clicking a button and to that button i want to add class 单击提交按钮时获取多个div中输入字段的值 - Get the value of an input field within multiple divs when clicking a submit button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM