Henry- 2016-05-05 20:23:33 2812次浏览 1条回复 0 0 0

对一个form表单中的字段怎么添加id? 在下面的表单中,怎么给name添加id 我看别人的代码 在js有用到id 但没看到怎么添加的id。求指点,附代码 view表单

<?php $form = ActiveForm::begin([
    'id' => 'login-form',
    'method' => 'post',
    'options' => ['enctype' => 'multipart/form-data'],
    'fieldConfig' => [
        'template' => '{label}<div class="col-sm-6">{input}{error}</div>',
                  'labelOptions' => ['class' => 'col-sm-2 control-label'],
                  'inputOptions' => ['class' => 'form-control']
                 ]
]); ?>

<?= $form->field($model, 'name', ['template' => '{label}<div class="col-sm-6">{input}{error}</div><div class="col-sm-1"><a class="btn btn-primary" onclick="translationVal(\'brand-name\')">翻译</a></div>'])->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'name_en')->textInput(['maxlength' => true]) ?>

jq代码

function translationVal(thisObj) {
    var k = $('#' + thisObj).val();
    if (k == '') {
        layer.msg('内容不能为空', {time: 2000, icon: 5});
        return false;
    }
    $.ajax({
        url: "/index.php?r=/video/translation",
        data: {k: k},
        dataType: "json",
        type: "post",
        success: function (data) {
            console.log(data.res);
            $('#' + thisObj + '_en').val(data.res);
        }
    });
}
您需要登录后才可以回复。登录 | 立即注册