此代码采用visualforce(salesforce的页面编辑器语言)。基本上,apex:repeat标签用作一种循环,从outputlink生成一组url。所有这些网址都有一类“名称”。
jquery要做的是找到所有带有类名的url,然后单击它们以便在新窗口中打开它们。它不起作用。
<apex:page standardcontroller="Account" extensions="maininvoice">
<apex:repeat value="{!theListOfIDs}" var="anId">
<apex:outputLink target="_blank" value="{!URLFOR($Page.invoice2,anId)}" styleClass="name" />
</apex:repeat>
<apex:includeScript value="{!URLFOR($Resource.jquery, 'js/jquery-1.4.2.min.js')}"/>
<script type="text/javascript">
var j$ = jQuery.noConflict();
j$(document).ready(function(){
$('.name').click();
alert("debug");
}
);
</script>
</apex:page>
答案 0 :(得分:2)
.click()
不会导致默认行为发生(例如,在链接/打开窗口之后),如果您希望发生这种情况,则必须自己调用window.open()
,例如这样:
var j$ = jQuery.noConflict();
j$(function(){
$('.name').each(function() {
window.open(this.href);
});
alert("debug");
});
但请注意,大多数浏览器会阻止您这样做,不确定在那里推荐什么,而且我个人也不喜欢在页面加载时打开窗口。