我有以下 HTML:
<span style="margin-top: -2px;">
<select id="selectID" style="width: 150px">
<option value="customerID">Customer ID</option>
<option value="ECPDProfileID">ECPD Profile ID</option>
</select>
</span>
<input type="text" id="customerProfileID" placeholder="here"/>
我试图根据选择选项中选择的值更改占位符值。
我为此尝试了以下 jQuery 代码:
<script type="text/javascript">
$(document).ready(function(){
var v = $("#selectID").val();
$("#customerProfileID").attr('placeholder', v);
});
</script>
此代码仅在页面第一次加载时更改占位符的值一次,因为我知道我将它保存在文档就绪函数中。我想根据在选择选项中选择的值来更改占位符的值。我需要打另一个电话还是可以从文档准备功能或任何其他解决方案内部进行?