在规则中
public function rules() { return [ [ 'nonmember_name', 'required', 'when' => function ($model) { return $model->is_member == 2; }, 'whenClient' => "function (attribute, value) { return $('#id').val() == '2'; }" ] ]; }