2016-02-29 54 views
0

我需要修改使用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用默认值,并更改每次选择更改值的选项。根据选择

$('#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

您可以添加最初呈现的HTML? – RRK

+0

最初的HTML?你什么意思? – hateful

+0

从页面源加载页面时的输入和其他元素的html。 – RRK

回答

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'); 
    } 
}) 
0

这里是我的情况下工作的代码,

$(this).closest('div').find('label').html('Change')