【问题标题】:The value of a array has to become an input field数组的值必须成为输入字段
【发布时间】:2016-02-18 13:27:51
【问题描述】:

这是我的数组

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

            );

如何让“其他”更改我在输入字段“其他兴趣”中输入的内容?

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

当我选择其他时,jQuery 会显示输入字段

  <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>

【问题讨论】:

  • 这是下拉列表的id

标签: jquery arrays input field


【解决方案1】:

我从您的问题中了解到,您希望在输入字段中显示“其他”:“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(); 
    }
  });
 });

【讨论】:

  • 嗯不哈哈,当我选择其他时,我输入例如'test'然后其他将成为我数据库中的测试
  • 哦!你的问题很不清楚......完全被误解了。 “other_interest”是您表单的一部分,对吧?
  • 当我按“其他”时,“other_interest”会出现在我的表单中,所以我想在“other_interest”中添加一些文本,但是当我保存它时。 “只有其他的出现,而不是我想要的文字。
猜你喜欢
  • 1970-01-01
  • 2016-04-26
  • 2019-06-20
  • 1970-01-01
  • 1970-01-01
  • 2019-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多