【发布时间】:2014-09-24 10:31:30
【问题描述】:
我有一个选择框,其中有几个选项可供用户选择,当用户选择“名字”时,我希望占位符文本“输入您的名字”出现在文本框旁边。 请在下面找到我的一段代码:
HTML:
<select id="selectionType">
<option value="-1">Select One</option>
<option value="0">First Name</option>
<option value="1">Last Name</option>
JS:
var placeholderText = {"First Name":"Enter your First Name","Last Name":"Enter your Last Name"};
$("#selectionType").on("change",function() {
var selection = document.getElementById("selectionType");
var inputBox = document.getElementById("inputBox");
var selectedVal = $('#selectionType').find(':selected').text();
if (placeholderText[selectedVal] !== undefined) {
inputBox.placeholder = placeholderText[selectedVal];
}
});
它在 Chrome 和 FF 中运行良好,但在 IE 8 和 9 中失败... 对此有任何帮助。
【问题讨论】:
-
IE 8,9 不支持占位符。 Check this for a solution
标签: javascript jquery html placeholder