1

我在页面上有一组连接的 Web 部件。基本上这些都是开箱即用的 webparts 并且是连接的。提供者和消费者在用户名字段 (donmain\userName) 上连接。因此,从提供者 Web 部件中选择一个值会更新所有消费者 Web 部件数据。

现在我的问题是,我想从 webpart 中获取所选项目,所选项目有一个“img”标签,其“alt”文本为“已选择”,因此基于此我想获取下一个元素的所选文本.

这是我的标记,我希望从标记中返回值“domain\test.officer”,因为它是所选项目。

            <TABLE id={2E5002B0-EDC3-4541-A0ED-2A81797B459C}-{F1162455-D63E-481D-B13C-C1A4A59E5A34} class=ms-listviewtable border=0 cellSpacing=0 summary="Trainee " cellPadding=1 width="100%" xmlns:o="urn:schemas-microsoft-com:office:office" o:WebQuerySourceHref="http://test.app.domain.net/test/_vti_bin/owssvr.dll?CS=65001&amp;XMLDATA=1&amp;RowLimit=0&amp;View={F1162455-D63E-481D-B13C-C1A4A59E5A34}" handleDeleteInit="true"><TBODY>
            <TR class="ms-viewheadertr ms-vhltr" vAlign=top>
            <TH class=ms-vh-icon scope=col><INPUT class=s4-selectAllCbx title="Select or deselect all items" onclick=ToggleAllItems(event,this,159) value="" type=checkbox></TH>
            <TH class=ms-vh2 onmouseover=OnChildColumn(this) scope=col noWrap>
            <DIV class=ms-vh-div name="SelectTitle" SortFields="View={f1162455-d63e-481d-b13c-c1a4a59e5a34}&amp;SortField=SelectTitle&amp;SortDir=Asc" ResultType="" FieldType="Computed" DisplayName="Select" CTXNum="159" FilterDisableMessage="" Filterable="FALSE" FilterDisable="" SortDisable="" Sortable="FALSE">Select</DIV></TH>
            <TH class=ms-vh-icon onmouseover=OnChildColumn(this) scope=col noWrap>
            <DIV class=ms-vh-div name="Attachments" SortFields="View={f1162455-d63e-481d-b13c-c1a4a59e5a34}&amp;SortField=Attachments&amp;SortDir=Asc" ResultType="" FieldType="Attachments" DisplayName="Attachments" CTXNum="159" FilterDisableMessage="" Filterable="" FilterDisable="" SortDisable="" Sortable=""><A id=diidSortAttachments onfocus=OnFocusFilter(this) onclick="javascript:return OnClickFilter(this,event);" href="javascript: " SortingFields="View={f1162455-d63e-481d-b13c-c1a4a59e5a34}&amp;SortField=Attachments&amp;SortDir=Asc"><IMG border=0 src="/_layouts/images/attachhd.gif"><IMG class=ms-hidden border=0 alt="Use SHIFT+ENTER to open the menu (new window)." src="/_layouts/images/blank.gif" width=1 height=1></A><IMG border=0 alt="" src="/_layouts/images/blank.gif"><IMG border=0 alt="" src="/_layouts/images/blank.gif"></DIV>
            <DIV class=s4-ctx><SPAN>&nbsp;</SPAN><A onfocus="OnChildColumn(this.parentNode.parentNode); return false;" title="Open Menu" onclick="PopMenuFromChevron(event); return false;" href="javascript:;"></A><SPAN>&nbsp;</SPAN></DIV></TH>
            <TH class=ms-vh2 onmouseover=OnChildColumn(this) scope=col noWrap>
            <DIV class=ms-vh-div name="LinkTitle" SortFields="View={f1162455-d63e-481d-b13c-c1a4a59e5a34}&amp;SortField=LinkTitle&amp;SortDir=Asc" ResultType="" FieldType="Computed" DisplayName="Title" CTXNum="159" FilterDisableMessage="" Filterable="" FilterDisable="" SortDisable="" Sortable=""><A id=diidSortLinkTitle onfocus=OnFocusFilter(this) onclick="javascript:return OnClickFilter(this,event);" href="javascript: " SortingFields="View={f1162455-d63e-481d-b13c-c1a4a59e5a34}&amp;SortField=LinkTitle&amp;SortDir=Asc">Title<IMG class=ms-hidden border=0 alt="Use SHIFT+ENTER to open the menu (new window)." src="/_layouts/images/blank.gif" width=1 height=1></A><IMG border=0 alt="" src="/_layouts/images/blank.gif"><IMG border=0 alt="" src="/_layouts/images/blank.gif"></DIV>
            <DIV class=s4-ctx><SPAN>&nbsp;</SPAN><A onfocus="OnChildColumn(this.parentNode.parentNode); return false;" title="Open Menu" onclick="PopMenuFromChevron(event); return false;" href="javascript:;"></A><SPAN>&nbsp;</SPAN></DIV></TH></TR>
            <TR class=ms-itmhover iid="159,9,0" setEdgeBorder="true">
            <TD class="ms-vb-itmcbx ms-vb-firstCell"><INPUT class=s4-itm-cbx title="domain\test.user1&#13;&#10;  " value="" type=checkbox _setup="true"></TD>
            <TD class=ms-vb2><IMG style="CURSOR: hand" border=0 alt=Selected align=absMiddle src="/_layouts/images/rbsel.gif"></TD>
            <TD class=ms-vb2></TD>
            <TD class="ms-vb-title ms-vb-lastCell" onmouseover=OnChildItem(this) height="100%">
            <DIV id=9 class="ms-vb itx" onmouseover=OnItem(this) EventType="" Perm="0x7fffffffffffffff" Field="LinkTitle" CTXName="ctx159"><A onfocus=OnLink(this) onclick="EditLink2(this,159);return false;" href="http://test.app.domain.net/test/_layouts/listform.aspx?PageType=4&amp;ListId={2E5002B0-EDC3-4541-A0ED-2A81797B459C}&amp;ID=9&amp;ContentTypeID=0x0100801F054C4E00C243A9A49EC13FF778D7003293EF8DE37E144BAA8A5296D5E6CA8B" target=_self>domain\test.user1</A><IMG class=ms-newgif title=New alt=New src="/_layouts/1033/images/new.gif"></DIV>
            <DIV class=s4-ctx onmouseover="OnChildItem(this.parentNode); return false;"><SPAN>&nbsp;</SPAN><A onfocus="OnChildItem(this.parentNode.parentNode); return false;" title="Open Menu" onclick="PopMenuFromChevron(event); return false;" href="javascript:;"></A><SPAN>&nbsp;</SPAN></DIV></TD></TR>
            <TR class="ms-alternating ms-itmhover" iid="159,8,0" setEdgeBorder="true">
            <TD class="ms-vb-itmcbx ms-vb-firstCell"><INPUT class=s4-itm-cbx title="domain\test.officer&#13;&#10;  " value="" type=checkbox _setup="true"></TD>
            <TD class=ms-vb2><A onclick="SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','8');return false;" href="javascript:SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','8');return false;" target=_self><IMG style="CURSOR: hand" border=0 alt=Normal align=absMiddle src="/_layouts/images/rbunsel.gif"></A></TD>
            <TD class=ms-vb2></TD>
            <TD class="ms-vb-title ms-vb-lastCell" onmouseover=OnChildItem(this) height="100%">
            <DIV id=8 class="ms-vb itx" onmouseover=OnItem(this) EventType="" Perm="0x7fffffffffffffff" Field="LinkTitle" CTXName="ctx159"><A onfocus=OnLink(this) onclick="EditLink2(this,159);return false;" href="http://test.app.domain.net/test/_layouts/listform.aspx?PageType=4&amp;ListId={2E5002B0-EDC3-4541-A0ED-2A81797B459C}&amp;ID=8&amp;ContentTypeID=0x0100801F054C4E00C243A9A49EC13FF778D7003293EF8DE37E144BAA8A5296D5E6CA8B" target=_self>domain\test.officer</A><IMG class=ms-newgif title=New alt=New src="/_layouts/1033/images/new.gif"></DIV>
            <DIV class=s4-ctx onmouseover="OnChildItem(this.parentNode); return false;"><SPAN>&nbsp;</SPAN><A onfocus="OnChildItem(this.parentNode.parentNode); return false;" title="Open Menu" onclick="PopMenuFromChevron(event); return false;" href="javascript:;"></A><SPAN>&nbsp;</SPAN></DIV></TD></TR>
            <TR class=ms-itmhover iid="159,5,0" setEdgeBorder="true">
            <TD class="ms-vb-itmcbx ms-vb-firstCell"><INPUT class=s4-itm-cbx title="domain\n.test&#13;&#10;  " value="" type=checkbox _setup="true"></TD>
            <TD class=ms-vb2><A onclick="SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','5');return false;" href="javascript:SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','5');return false;" target=_self><IMG style="CURSOR: hand" border=0 alt=Normal align=absMiddle src="/_layouts/images/rbunsel.gif"></A></TD>
            <TD class=ms-vb2></TD>
            <TD class="ms-vb-title ms-vb-lastCell" onmouseover=OnChildItem(this) height="100%">
            <DIV id=5 class="ms-vb itx" onmouseover=OnItem(this) EventType="" Perm="0x7fffffffffffffff" Field="LinkTitle" CTXName="ctx159"><A onfocus=OnLink(this) onclick="EditLink2(this,159);return false;" href="http://test.app.domain.net/test/_layouts/listform.aspx?PageType=4&amp;ListId={2E5002B0-EDC3-4541-A0ED-2A81797B459C}&amp;ID=5&amp;ContentTypeID=0x0100801F054C4E00C243A9A49EC13FF778D7003293EF8DE37E144BAA8A5296D5E6CA8B" target=_self>domain\n.test</A><IMG class=ms-newgif title=New alt=New src="/_layouts/1033/images/new.gif"></DIV>
            <DIV class=s4-ctx onmouseover="OnChildItem(this.parentNode); return false;"><SPAN>&nbsp;</SPAN><A onfocus="OnChildItem(this.parentNode.parentNode); return false;" title="Open Menu" onclick="PopMenuFromChevron(event); return false;" href="javascript:;"></A><SPAN>&nbsp;</SPAN></DIV></TD></TR>
            <TR class="ms-alternating ms-itmhover" iid="159,3,0" setEdgeBorder="true">
            <TD class="ms-vb-itmcbx ms-vb-firstCell"><INPUT class=s4-itm-cbx title="domain\test1.user1&#13;&#10;  " value="" type=checkbox _setup="true"></TD>
            <TD class=ms-vb2><A onclick="SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','3');return false;" href="javascript:SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','3');return false;" target=_self><IMG style="CURSOR: hand" border=0 alt=Normal align=absMiddle src="/_layouts/images/rbunsel.gif"></A></TD>
            <TD class=ms-vb2></TD>
            <TD class="ms-vb-title ms-vb-lastCell" onmouseover=OnChildItem(this) height="100%">
            <DIV id=3 class="ms-vb itx" onmouseover=OnItem(this) EventType="" Perm="0x7fffffffffffffff" Field="LinkTitle" CTXName="ctx159"><A onfocus=OnLink(this) onclick="EditLink2(this,159);return false;" href="http://test.app.domain.net/test/_layouts/listform.aspx?PageType=4&amp;ListId={2E5002B0-EDC3-4541-A0ED-2A81797B459C}&amp;ID=3&amp;ContentTypeID=0x0100801F054C4E00C243A9A49EC13FF778D7003293EF8DE37E144BAA8A5296D5E6CA8B" target=_self>domain\test1.user1</A><IMG class=ms-newgif title=New alt=New src="/_layouts/1033/images/new.gif"></DIV>
            <DIV class=s4-ctx onmouseover="OnChildItem(this.parentNode); return false;"><SPAN>&nbsp;</SPAN><A onfocus="OnChildItem(this.parentNode.parentNode); return false;" title="Open Menu" onclick="PopMenuFromChevron(event); return false;" href="javascript:;"></A><SPAN>&nbsp;</SPAN></DIV></TD></TR>
            <TR class=ms-itmhover iid="159,2,0" setEdgeBorder="true">
            <TD class="ms-vb-itmcbx ms-vb-firstCell"><INPUT class=s4-itm-cbx title="domain\admin.user&#13;&#10;  " value="" type=checkbox _setup="true"></TD>
            <TD class=ms-vb2><A onclick="SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','2');return false;" href="javascript:SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','2');return false;" target=_self><IMG style="CURSOR: hand" border=0 alt=Normal align=absMiddle src="/_layouts/images/rbunsel.gif"></A></TD>
            <TD class=ms-vb2></TD>
            <TD class="ms-vb-title ms-vb-lastCell" onmouseover=OnChildItem(this) height="100%">
            <DIV id=2 class="ms-vb itx" onmouseover=OnItem(this) EventType="" Perm="0x7fffffffffffffff" Field="LinkTitle" CTXName="ctx159"><A onfocus=OnLink(this) onclick="EditLink2(this,159);return false;" href="http://test.app.domain.net/test/_layouts/listform.aspx?PageType=4&amp;ListId={2E5002B0-EDC3-4541-A0ED-2A81797B459C}&amp;ID=2&amp;ContentTypeID=0x0100801F054C4E00C243A9A49EC13FF778D7003293EF8DE37E144BAA8A5296D5E6CA8B" target=_self>domain\admin.user</A></DIV>
            <DIV class=s4-ctx onmouseover="OnChildItem(this.parentNode); return false;"><SPAN>&nbsp;</SPAN><A onfocus="OnChildItem(this.parentNode.parentNode); return false;" title="Open Menu" onclick="PopMenuFromChevron(event); return false;" href="javascript:;"></A><SPAN>&nbsp;</SPAN></DIV></TD></TR>
            <TR class="ms-alternating ms-itmhover" iid="159,1,0" setEdgeBorder="true">
            <TD class="ms-vb-itmcbx ms-vb-firstCell"><INPUT class=s4-itm-cbx title="domain\portal.user&#13;&#10;  " value="" type=checkbox _setup="true"></TD>
            <TD class=ms-vb2><A onclick="SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','1');return false;" href="javascript:SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','1');return false;" target=_self><IMG style="CURSOR: hand" border=0 alt=Normal align=absMiddle src="/_layouts/images/rbunsel.gif"></A></TD>
            <TD class=ms-vb2></TD>
            <TD class="ms-vb-title ms-vb-lastCell" onmouseover=OnChildItem(this) height="100%">
            <DIV id=1 class="ms-vb itx" onmouseover=OnItem(this) EventType="" Perm="0x7fffffffffffffff" Field="LinkTitle" CTXName="ctx159"><A onfocus=OnLink(this) onclick="EditLink2(this,159);return false;" href="http://test.app.domain.net/test/_layouts/listform.aspx?PageType=4&amp;ListId={2E5002B0-EDC3-4541-A0ED-2A81797B459C}&amp;ID=1&amp;ContentTypeID=0x0100801F054C4E00C243A9A49EC13FF778D7003293EF8DE37E144BAA8A5296D5E6CA8B" target=_self>domain\portal.user</A></DIV>
            <DIV class=s4-ctx onmouseover="OnChildItem(this.parentNode); return false;"><SPAN>&nbsp;</SPAN><A onfocus="OnChildItem(this.parentNode.parentNode); return false;" title="Open Menu" onclick="PopMenuFromChevron(event); return false;" href="javascript:;"></A><SPAN>&nbsp;</SPAN></DIV></TD></TR></TBODY></TABLE>
4

1 回答 1

2

您可以使用 SharePoint 2010 客户端对象模型方法“ SP.ListOperation.Selection.getSelectedItems() ”来获取所选项目。

在内容编辑器 Webpart 中尝试此脚本:

<script type="text/javascript">

 function ShowSelectedItems() {
  var ctx = SP.ClientContext.get_current();
  var selectedItems = SP.ListOperation.Selection.getSelectedItems(ctx);
  var key;
  for (key in selectedItems) {
   alert(selectedItems[key].id);
  }


 }</script>
 <input name="btnShowSelectedItems" id="btnShowSelectedItems" onclick="ShowSelectedItems();" type="button" value="Show Selected Items"/> 

我不会推荐这个,但如果你真的想用这个来使用 jQuery,你可以试试这个脚本:

var selectedImg$ = $('img[alt^="Selected"]');
var elemID = selectedImg$.closest('tr').attr('iid').split(',')[1];
var linkText = selectedImg$.closest('tr').find('div#'+elemID).find('a').text();
于 2012-09-28T07:59:32.703 回答