一个数组的值有可能成为一个输入字段 [英] The value of a array has to become an input field

查看:177
本文介绍了一个数组的值有可能成为一个输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的数组

  $ M3 =阵列
          (
           '2'= GT; '2',
           '4'= GT; '4',
           '6'=> '6',
           '9'=> 9,
           '14'=> '14',
           '18'=> '18',
           '20'=> 20,
           '其他'=> '其他'            );

我如何获得其他,在今天我把'other_interest的inputfield改变?

<?pre> &LT; = $形式 - &GT;输入(汽车/立方米,阵列('名'=&gt;中other_interest,风格=&gt;中显示:无,阶级= GT;'的inputText','标签'=&GT; FALSE));?&GT;

jQuery的显示,当我选择inputfield其他

 &LT;脚本&GT;
 jQuery的(文件)。就绪(函数(){
    jQuery的(#CarM3)。改变(函数(){
        如果(jQuery的(本).VAL()==='其他'){
            jQuery的(输入[名称= other_interest]')显示()。
         }其他{
            。jQuery的(输入[名称= other_interest]')隐藏();
        }
     });
});
&LT; / SCRIPT&GT;


解决方案

我从你的问题明白的是,你要等,以显示在inputfield:other_interest。

 &LT;脚本&GT;
  jQuery的(文件)。就绪(函数(){
  jQuery的(#CarM3)。改变(函数(){
    如果(jQuery的(本).VAL()==='其他'){
        jQuery的(输入[名称= other_interest]')显示()。
        //在上述行,你只是显示inputfield
        jQuery的(输入[名称= other_interest]')。VAL(其他)//加入这一行应该为你做的伎俩!     }其他{
        。jQuery的(输入[名称= other_interest]')隐藏();
    }
  });
 });

this is my array

        $m3 = array
          (
           '2' => '2',
           '4' => '4',
           '6' => '6',
           '9' => '9',
           '14' => '14',
           '18' => '18',
           '20' => '20',
           'other' => 'other'

            );

How do I get 'other' to change in what I put in the inputfield 'other_interest'?

   <?=$form->input('Car/m3', array('name' => "other_interest", 'style' =>        "display:none", 'class' => 'inputText', 'label' => false));?>

The jQuery shows the inputfield when I choose other

  <script>
 jQuery(document).ready(function() {
    jQuery("#CarM3").change(function() {
        if (jQuery(this).val() === 'other'){ 
            jQuery('input[name=other_interest]').show();   
         } else {
            jQuery('input[name=other_interest]').hide(); 
        }
     });
});
</script>

解决方案

What I understand from your question is that, you want "other" to be displayed in the inputfield : "other_interest".

  <script>
  jQuery(document).ready(function() {
  jQuery("#CarM3").change(function() {
    if (jQuery(this).val() === 'other'){ 
        jQuery('input[name=other_interest]').show();   
        //in the above line, you are just displaying the inputfield
        jQuery('input[name=other_interest]').val("other") //adding this line should do the trick for you!

     } else {
        jQuery('input[name=other_interest]').hide(); 
    }
  });
 });

这篇关于一个数组的值有可能成为一个输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆