通过<option>更改输入的占位符

时间:2016-02-08 18:44:26

标签: javascript jquery html onclick onchange

我需要一些帮助,通过<select>

更改输入的占位符

我的意思是如果<select>的选项已更改,我需要更改输入的占位符

我的代码:

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

1 个答案:

答案 0 :(得分:0)

试试这个:

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

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

相关问题