如何删除 select 上的名称并使用 javascript 或 jquery 在文本区域中添加名称?

How can I remove name on the select and add the name on the textarea with javascript or jquery?

我的 html 代码是这样的:

$('input[name="is_follow_up"]').change(function(){
        var val = $(this).val(),
            input = $('.input-reason');
        if (val == 'n') 
            input.show()
        else 
            input.hide();
    });
    $('.select-reason').change(function(){
        var reason = $(this).val(),
            others = $('.textarea-others');
        if (reason == 4) 
            others.show();
        else 
            others.hide()
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label class="radio-inline">
        <input type="radio" name="is_follow_up" id="inlineRadio1" value="y" required checked> accept
    </label>
    <label class="radio-inline">
        <input type="radio" name="is_follow_up" id="inlineRadio2" value="n" required> reject
    </label>
    <div class="row input-reason" style="display: none">
        <div class="col-sm-2">Reason:</div>
        <div class="col-sm-5">
            <div class="form-group">
                <select class="form-control select-reason" name="reason">
                    <option value="Reason 1">Reason 1</option>
                    <option value="Reason 2">Reason 2</option>
                    <option value="Reason 3">Reason 3</option>
                    <option value="4">Reason 4</option>
                </select>
            </div>
            <div class="form-group textarea-others" style="display: none">
            <textarea rows="5" class="form-control"></textarea>
            </div>
        </div>
    </div>
我想要如果用户 select 原因 4,它将删除 select 标签上的 name="reason" 并在 textarea 标签

上添加 name="reason"

我该怎么做?

那么你可以简单地使用jQuery来remove/add命名属性

$('.select-reason').change(function(){
    var reason = $(this).val(),
        others = $('.textarea-others');
    if (reason === '4') { 
        others.show();
        $(this).removeAttr('name');
        others.find('textarea').attr('name', 'reason');
    } else { 
        others.hide();
    }
});