試試這個:
HTML:
<input class="numberEntry" name="howMany" type="text" />
的jQuery:
$(document).ready(function() {
// get the name from the existing text entry input
var numberEntryName = $(".numberEntry").attr("name");
// create some new HTML to replace our input with
var numberSelector = '';
// make the select box
numberSelector += '<select name="' + numberEntryName + '">';
for (var i = 0; i <= 10; i++)
{
numberSelector += '<option value="' + i + '">' + i + '</option>';
}
// add the more link
numberSelector += '<option value="MORE">- More -</option>';
numberSelector += '</select>';
// now grab the existing input field so we can display it later when
// the user clicks on the more link
var numberEntryHtml = $(".numberEntry").wrap("<div>").html();
// replace the existing input field with our new HTML
$(".numberEntry").replaceWith(numberSelector);
// add a click event to the more link so that we'll show our
// old text input field when "more" is clicked
$("select[name=" + numberEntryName + "]").bind("change", function(e) {
if ($(this).val() == "MORE")
$(this).replaceWith(numberEntryHtml);
});
});
此代碼是未經測試,但它應該給你的設計模式的想法。
這很好,但用戶想要一個選項標籤----更多---- – bendewey 2009-02-11 01:50:24