我正在使用 jQuery 占位符插件(https://github.com/danielstocks/jQuery- Placeholder)。我需要通过下拉菜单中的更改来更改占位符文本。但它没有改变。这是代码:
$(function () { $('input[placeholder], textarea[placeholder]').placeholder(); $('#serMemdd').change(function () { var k = $(this).val(); if (k == 1) { $("#serMemtb").attr("placeholder", "Type a name (Lastname, Firstname)").placeholder(); } else if (k == 2) { $("#serMemtb").attr("placeholder", "Type an ID").placeholder(); } else if (k == 3) { $("#serMemtb").attr("placeholder", "Type a Location").placeholder(); } }); });
我的HTML:
<div class="filterbox"> <select name="ddselect" id="serMemdd"> <option value="1" selected="selected">Search by Name</option> <option value="2">Search by ID</option> <option value="3">Search by Location</option> </select> <input id="serMemtb" type="text" style="width: 490px" placeholder="Type a name (Lastname, Firstname)" /> <input id="seMemBut" type="button" value="Search" /> </div>
任何人都可以解决这个问题吗?
$(document).ready(function(){ $('form').find("input[type=textarea], input[type=password], textarea").each(function(ev) { if(!$(this).val()) { $(this).attr("placeholder", "Type your answer here"); } }); });
将此代码复制并粘贴到您的 js 文件中,这将更改整个站点的所有占位符文本。