我目前有一个js函数,只有在网格上有变化时才会将更改绑定到onbeforeunload或确认框。
我正在尝试选择页脚分页锚点,以便它不会触发确认或onbeforeunload。无论网格上是否有变化,用户都应选择数字分页。
锚点上没有ID或类名,因此我无法访问它。
提前致谢。
RadGrid属性:
<telerik:RadGrid
runat="server"
ID="DataGridFooItems"
AllowSorting="true"
AutoGenerateColumns="false"
EnableViewState="True"
GridLines="Vertical"
AllowPaging="True"
PagerStyle-Mode="NumericPages">
<MasterTableView
AllowPaging="true"
DataKeyNames="foopersonID,fooItemID"
AllowAutomaticDeletes="true"
CommandItemDisplay="None"
NoMasterRecordsText="" >
这就是.aspx在下面生成的内容:
<TFOOT>
<TR class=rgPager>
<TD colSpan=20>
<TABLE style="WIDTH: 100%" border=0 cellSpacing=0>
<TBODY>
<TR>
<TD class="rgPagerCell NumericPages">
<DIV class="rgWrap rgNumPart">
<A class=rgCurrentPage onclick="returnfalse;"href="javascript:__doPostBack('ctl00$ph$FOO$rgItems$ctl00$ctl03$ctl01$ctl02','')"><SPAN>1</SPAN></A><A
href="javascript:__doPostBack('ctl00$ph$FOO$rgItems$ctl00$ctl03$ctl01$ctl04','')"><SPAN>2</SPAN></A><A
href="javascript:__doPostBack('ctl00$ph$FOO$rgItems$ctl00$ctl03$ctl01$ctl06','')"><SPAN>3</SPAN></A><A
href="javascript:__doPostBack('ctl00$ph$FOO$rgItems$ctl00$ctl03$ctl01$ctl08','')"><SPAN>4</SPAN></A><A
href="javascript:__doPostBack('ctl00$ph$FOO$rgItems$ctl00$ctl03$ctl01$ctl10','')"><SPAN>5</SPAN></A><A
href="javascript:__doPostBack('ctl00$ph$FOO$rgItems$ctl00$ctl03$ctl01$ctl12','')"><SPAN>6</SPAN></A><A
href="javascript:__doPostBack('ctl00$ph$FOO$rgItems$ctl00$ctl03$ctl01$ctl14','')"><SPAN>7</SPAN></A><A
href="javascript:__doPostBack('ctl00$ph$FOO$rgItems$ctl00$ctl03$ctl01$ctl16','')"><SPAN>8</SPAN></A><A
href="javascript:__doPostBack('ctl00$ph$FOO$rgItems$ctl00$ctl03$ctl01$ctl18','')"><SPAN>9</SPAN></A><A
href="javascript:__doPostBack('ctl00$ph$FOO$rgItems$ctl00$ctl03$ctl01$ctl20','')"><SPAN>10</SPAN></A><A
href="javascript:__doPostBack('ctl00$ph$FOO$rgItems$ctl00$ctl03$ctl01$ctl22','')"><SPAN>...</SPAN></A>
</DIV></TD></TR></TBODY></TABLE></TD></TR></TFOOT>
更新:回答!
发现它!通过一些研究和调整类似的Telerik解决方案。我写了这个:
function preventPromptOnFooter() {
var pagerCell = $('[class="rgPagerCell NumericPages"]')
var anchors = $(pagerCell).find('a');
for (var i = 0; i < anchors.length; i++) {
if (anchors[i].className != "rgCurrentPage" && anchors[i].href.indexOf("javascript:__doPostBack") > -1) {
var clickScript = anchors[i].attributes["onclick"].value;
anchors[i].onclick = disableOnbeforeUnloadForFooter;
}
}
function disableOnbeforeUnloadForFooter() {
window.onbeforeunload = null;
}
}
答案 0 :(得分:0)
你可以尝试:
var pageLinks = document.querySelectorAll(".rgWrap.rgNumPart a");
适用于Chrome,Firefox 3.5 +,ie8 +,Opera 10和Safari 3.2+。如果您必须支持旧浏览器,您可以尝试将父div除以其类名,然后使用getElementsByTagName('A')。或者使用像jQuery这样的库来跨浏览器实现高级CSS选择器。
答案 1 :(得分:0)
我写了这个:
function preventPromptOnFooter() {
var pagerCell = $('[class="rgPagerCell NumericPages"]')
var anchors = $(pagerCell).find('a');
for (var i = 0; i < anchors.length; i++) {
if (anchors[i].className != "rgCurrentPage" && anchors[i].href.indexOf("javascript:__doPostBack") > -1) {
var clickScript = anchors[i].attributes["onclick"].value;
anchors[i].onclick = disableOnbeforeUnloadForFooter;
}
}
function disableOnbeforeUnloadForFooter() {
window.onbeforeunload = null;
}
}