What is wrong with my jquery javascript here?
So I'm attempting to make a page in Visualforce(salesforce's page creator), and am having issues with the javascript aspect of it. Basically what should happen is that the section will generate a series of links. The javascript needs to click those links. I'm using jquery
<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>
<ape开发者_Python百科x:includeScript value="{!URLFOR($Resource.jquery, 'js/jquery-1.4.2.min.js')}"/>
<script type="text/javascript">
var j$ = jQuery.noConflict();
j$(document).ready(function(){
var anchortags = j$('.name');
for(i=0;i<=anchortags.length;i++){
var currentTag=anchortags[i];
currentTag.trigger(click);
alert("your mother");
}
}
);
</script>
</apex:page>
Answering your exact question, this: currentTag.trigger(click);
should be: currentTag.trigger('click');
But, come on, jQuery
can do this all for you in one shot:
$('.name').click();
You're sort-of mixing up jQuery coding with "traditional" coding, and it's not working. Try this:
var anchortags = j$('.name');
anchortags.click();
Something like this:
var j$ = jQuery.noConflict();
j$(function(){
j$('.name').click();
});
j$(function(){...});
is the same as j$(document).ready(function(){...});
The click()
function will be executed for every match in the previous list (j$('.name')
). Use of .each(function(){...});
is therefor redundant.
var j$ = jQuery.noConflict();
j$(document).ready(function(){
j$('.name').each(function() {
j$(this).trigger('click');
});
精彩评论