开发者

Calling JQuery function onload and onclick

开发者 https://www.devze.com 2023-03-28 09:05 出处:网络
I have a RadionButtonList with two values and on click I gotta hide some elements on my page. I got the following code that triggers on click on a RadionButton. How do I call this on the Page load of

I have a RadionButtonList with two values and on click I gotta hide some elements on my page.

I got the following code that triggers on click on a RadionButton. How do I call this on the Page load of my page?

$(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 {
    开发者_JS百科    $(this).css('display', 'inline');
        $(this).next('label').css('display', 'inline');
      }
    });
  });
});


You can trigger the click event right after you've registered your handler:

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


try

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

after your code


$(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();
});


Try this, just call the click method after you have attached the event handler.

$(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();
});
0

精彩评论

暂无评论...
验证码 换一张
取 消