我有這個輸入,有文本,當你點擊它,文本消失,但如果你沒有輸入任何文字將回來。jquery輸入複雜增加混亂
<input type="button" id="btnAdd" value="Add Answer" />
<input type="text" id="forminput" class="clonedInput" onclick="this.value='';"
onfocus="this.select()"onblur="this.value=!this.value?'Answer 1
':this.value;" value="Answer 1" />
我有一個按鈕,可以使用此功能克隆和增加當前輸入字段。
這是增加我當前輸入字段的函數,但我也需要遞增答案#。
$('#btnAdd').click(function() {
var num = $('.clonedInput').length; // how many "duplicatable" input fields we currently have
var newNum = new Number(num + 1); // the numeric ID of the new input field being added
// create the new element via clone(), and manipulate it's ID using newNum value
var newElem = $('#formanswer' + num).clone().attr('id', 'formanswer' + newNum);
// manipulate the name/id values of the input inside the new element
newElem.children(':first').attr('id', 'formanswer' + newNum).attr('value','Answer '+newNum);
// insert the new element after the last "duplicatable" input field
$('#formanswer' + num).after(newElem);
我的問題是,我需要增加新的輸入字段內的文本,使其每次克隆時動態增加一個。我一直在牆上靠着我的頭幾個小時,但我希望它不是一些簡單的PHP變種。 plz幫我:〜)
宕老兄,你最好!我不確定如何解決這個問題。感謝您在js小提琴2中顯示它。 – user1082764 2011-12-16 06:18:26