[英]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.