我需要修改使用CakePHP和JQuery在输入表单中创建的标签。
$info = "test";
echo $this->Form->input('tipo_de_venta', array('type' => 'select', 'label' => 'Tipo de venta'.$info, 'div' => 'required', 'options' => $opciones_tipo_venta));
我正在做的是设置一个带有默认值的变量$info
,每次更改select选项以更改值。取决于选择
$('#tipo_de_venta').on('change', function() {
console.log(this);
if(this.value == 1){
}
if(this.value == 0){
}
if(this.value == 2){
}
});
尝试$(this).text("Change");
,但它对我不起作用。
Html:
<div class="required">
<label for="EventoTipoDeVenta">Tipo de venta</label>
<select name="data[Evento][tipo_de_venta]" id="EventoTipoDeVenta">
<option value="0">Compra simple</option>
<option value="1">Change</option>
<option value="2" selected="selected">Compra multiple simplificada</option>
</select>
</div>
答案 0 :(得分:1)
试试这段代码
$('#tipo_de_venta').on('change', function() {
console.log(this);
if(this.value == 1){
$(this).closest('div').find('label').text('One');
}
if(this.value == 0){
$(this).closest('div').find('label').text('zero');
}
if(this.value == 2){
$(this).closest('div').find('label').text('two');
}
})
答案 1 :(得分:0)
以下是我的案例中的代码,
$(this).closest('div').find('label').html('Change')