我有一个有两个值的RadionButtonList,点击我要隐藏页面上的一些元素。
我得到了下面的代码,触发点击一个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');
}
});
});
});
您可以在注册处理程序后立即触发click
事件:
$('#<%= columnsRoundPanel.FindControl("rdlClickOrder").ClientID %> input')
.click(function() {
// Your handler...
}).click();
try
$('#<%= columnsRoundPanel.FindControl("rdlClickOrder").ClientID %> input').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();
});
试试这个,在您附加了事件处理程序之后,只调用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();
});