开发者

jquery trigger - 'change' function [duplicate]

This question already has an answer here: Closed 12 years ago. 开发者_运维知识库

Possible Duplicate:

jquery trigger - ‘change’ function

I have a radio button set called "pick_up_point" and I have a change handler to detect the radio button that is checked. In the change handler I call a function "clearFields()" which basically clears out the input fields.

function clearFields()
{
 $("#Enquiry_start_point").val("");
 $("#Enquiry_start_town").val("");
 $("#Enquiry_start_postcode").val("");
}

$("input[name='pick_up_point']").change(function()
{
 if($("input[name='pick_up_point']:checked").val() == "pick_up_airport")
 {
  $("#pick_up_airport_div").slideDown();
  $("#start_point_div").hide();
  clearFields();
 }
});

I also have a trigger which will retain the view if the form is redisplayed due to a validation error.

$('input[name=\'pick_up_point\']').trigger('change');

Now when I post the form the trigger is run and it calls the change handler, which of course runs the clearFields() function. So how can I get around this? I don't want the fields being cleared when the form is re-displayed.


Change your change function (sorry couldn't resist) to accept a parameter that tells you whether to clear fields or not.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜