【问题标题】:changing placeholder of an input via <option> [duplicate]通过 <option> [重复] 更改输入的占位符
【发布时间】:2016-02-08 18:44:25
【问题描述】:

我需要一些帮助来更改通过&lt;select&gt; 输入的占位符,

我的意思是,如果 &lt;select&gt; 的选项已更改,我需要更改输入的占位符

我的代码:

<select id="select" name="se">
   <!-- if this is chosen placeholder will be 'you have chosen option n1' !-->
   <option value="1">option 1</option>
   <!-- if this is chosen placeholder will be 'you have chosen option n2' !-->
   <option value="2">option 2</option>
   <!-- if this is chosen placeholder will be 'you have chosen option n3' !-->
   <option value="3">option 3</option>
</select>
<input type="text" id="inp" name="choosen">

【问题讨论】:

  • 您的意思是在文本框中显示所需的文本吗?
  • @DinoMyte 是的,我在说什么
  • 那是 value 而不是 placeholder。占位符是你在没有值时看到的提示
  • 您似乎还没有尝试解决自己的问题。 Please show what you've tried.

标签: javascript jquery html onclick onchange


【解决方案1】:

试试这个:

$('select').on("change",function()
{
   $('#inp').val("you have chosen option n" + $.trim(this.value));
}).change();

例如:https://jsfiddle.net/DinoMyte/zcL12b1u/1/

【讨论】:

    猜你喜欢
    • 2013-07-16
    • 1970-01-01
    • 1970-01-01
    • 2015-03-23
    • 1970-01-01
    • 2018-02-09
    • 2013-11-22
    • 2018-04-12
    • 2021-06-15
    相关资源
    最近更新 更多