,我想動態添加一個文本框一個按鈕,點擊jQuery的錯誤:微軟JScript運行時錯誤:無法獲得屬性「HTML」的值:對象爲空或我的MVC3剃鬚刀頁面上未定義
下面粘貼的是我的jquery。但是當我點擊addButton時,我收到上述錯誤消息。
要解決此錯誤,我嘗試添加<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
,但仍得到相同的錯誤。讚賞您的建議以解決此錯誤。
<script type="text/javascript">
$(document).ready(function(){
var counter = 2;
$("#addButton").click(function() {
if(counter>10){
alert("Only 10 textboxes allow");
return false;
}
var newTextBoxDiv = $(document.createElement('div')).attr("id", 'TextBoxDiv' + counter);
newTextBoxDiv.after().html('<label>Textbox #'+ counter + ' : </label>' +
'<input type="text" name="textbox' + counter +
'" id="textbox' + counter + '" value="" >');
newTextBoxDiv.appendTo("#TextBoxesGroup");
counter++;
});
$("#removeButton").click(function() {
if(counter==1){
alert("No more textbox to remove");
return false;
}
counter--;
$("#TextBoxDiv" + counter).remove();
});
$("#getButtonValue").click(function() {
var msg = '';
for(i=1; i<counter; i++){
msg += "\n Textbox #" + i + " : " + $('#textbox' + i).val();
}
alert(msg);
});
});
</script>
什麼是空的'.after()'調用? – Musa 2012-07-25 18:38:28