问题
This may not be possible with blade, but I was wondering how to generate a textbox input from an 'other' option in a select dropdown. Is this possible?
{{ Form::select('showType', array(
'Theater' => 'Theater',
'Club' => 'Club',
'Festival' => 'Festival',
'Arena' => 'Arena',
'Closed Show' => 'Closed Show',
'College Show' => 'College Show'
'Other' => 'some kind of text input appears instead'
)}}
回答1:
You'll need to use javascript to do that, Blade can't help much. But you can create, in Blade, your form input and set a hidden
class to it and, when your user select the 'other' option you just have to remove that class.
回答2:
You need to use JavaScript to do this because it happens on the client side. PHP and Laravel and Blade all happens on the server. An simple jQuery example:
$('select').on('change', function(){
$('body').append("<input type='text' value='whatever'/>");
});
来源:https://stackoverflow.com/questions/22993691/laravel-blade-form-is-it-possible-to-create-a-textbox-input-if-a-user-selects-t