我正在做一個非常簡單的方式和評論部分中的行爲像fb的節日賀卡,我似乎無法獲取和設置值在用戶添加新評論之後出現的動態創建的文本框......我創建了一個新的文本字段,其中包含用於識別它的id的附加數字,並且我可以在創建它的函數中設置該值,但一旦從另一個函數尋找它,代碼就會中斷。有任何想法嗎?我會認爲這可能取決於函數在文檔中的位置,但不確定。這裏有一個鏈接:如何獲取/設置動態創建的文本框的值
這是概括地說:
評論()包含以下代碼,修改輸入字段
// var subject = 'HI593F1' or something like that;
// var current_comment = new Array() and keeps count of the current new comment box
// this resulting value looks like this: 'comment-HI593F1-2'
var comment_field = 'comment-'+subject+'-'+current_comment[subject];
document.getElementById(comment_field).value = 'Write a comment...';
document.getElementById(comment_field).onblur = function() { ghost('comment', subject); }
document.getElementById(comment_field).onfocus = function() { unghost('comment', subject); }
document.getElementById(comment_field).onkeypress = function() { text_color('comment', subject); }
unghost()的工作原理是這個:
function unghost(field, number) { // field = 'comment' ... this is 'comment' because this function modifies more than one field var ogfield = field; // if another comment is expanded if (current) { collapse_comment(current); } current = number; // like var comment field in the comment() function if (number) { field = field+"-"+number+"-"+current_comment[number]; } // below is where the code breaks ... values[ogfield] = 'Write a comment...'; // should look like this: document.getElementById('comment-HI593F1-2').value == 'Write a comment...' if (document.getElementById(field).value == values[ogfield]) { document.getElementById(field).value = \'\'; } // change the color of the field text text_color(field, number); }
發佈相關代碼,我們將會看到。 – 2010-12-13 22:01:21
這是在提供的網址...只是查看源 – Lucas 2010-12-13 22:03:43
不,我不會那樣做。請在此發佈相關代碼,否則您無法真正期望來自這裏的人們提供多少幫助。 – 2010-12-13 22:09:27