2011-08-15 64 views
1

我有一个RadionButtonList有两个值,点击时我得隐藏我的页面上的一些元素。调用jQuery函数onload和onclick

我得到了下面的代码,点击RadionButton时触发。如何在我的网页的网页加载中调用此功能?

$(document).ready(function() { 
    $('#<%= columnsRoundPanel.FindControl("rdlClickOrder").ClientID %> input').click(function() { 
    var clickOrder = $(this).val(); 
    $('#<%= chkColumnList.ClientID %> input').each(function (i) { 
     var index = ($(this).next('label').text().indexOf(clickOrder)); 

     if ((index == -1) && ($(this).next('label').text() != 'Cost' && $(this).next('label').text() != 'Clicks' && $(this).next('label').text() != 'Impressions')) { 
     $(this).css('display', 'none'); 
     $(this).next('label').css('display', 'none'); 
     } else { 
     $(this).css('display', 'inline'); 
     $(this).next('label').css('display', 'inline'); 
     } 
    }); 
    }); 
}); 
+0

什么是RadionButtonList? jQuery没有这样的概念。 –

回答

0

尝试

$('#<%= columnsRoundPanel.FindControl("rdlClickOrder").ClientID %> input').click(); 

代码后

+0

或者只是替换后面的'}); });'带'})。click(); });'。 –

+0

@ TomalakGeret'kal:是的,也有可能。感谢您的建议! – genesis

0
$(document).ready(function() { 
    $('#<%= columnsRoundPanel.FindControl("rdlClickOrder").ClientID %> input').click(function() { 
    var clickOrder = $(this).val(); 
    $('#<%= chkColumnList.ClientID %> input').each(function (i) { 
     var index = ($(this).next('label').text().indexOf(clickOrder)); 

     if ((index == -1) && ($(this).next('label').text() != 'Cost' && $(this).next('label').text() != 'Clicks' && $(this).next('label').text() != 'Impressions')) { 
     $(this).css('display', 'none'); 
     $(this).next('label').css('display', 'none'); 
     } else { 
     $(this).css('display', 'inline'); 
     $(this).next('label').css('display', 'inline'); 
     } 
    }); 
    }).click(); 
}); 
1

可以触发事件click您已经注册了处理程序之后:

$('#<%= columnsRoundPanel.FindControl("rdlClickOrder").ClientID %> input') 
    .click(function() { 
     // Your handler... 
    }).click(); 
0

试试这个,只需拨打click方法后,您已附加事件处理程序。

$(document).ready(function() { 
    $('#<%= columnsRoundPanel.FindControl("rdlClickOrder").ClientID %> input').click(function() { 
    var clickOrder = $(this).val(); 
    $('#<%= chkColumnList.ClientID %> input').each(function (i) { 
     var index = ($(this).next('label').text().indexOf(clickOrder)); 

     if ((index == -1) && ($(this).next('label').text() != 'Cost' && $(this).next('label').text() != 'Clicks' && $(this).next('label').text() != 'Impressions')) { 
     $(this).css('display', 'none'); 
     $(this).next('label').css('display', 'none'); 
     } else { 
     $(this).css('display', 'inline'); 
     $(this).next('label').css('display', 'inline'); 
     } 
    }); 
    }).click(); 
});