[問題] javascript 必須要有物件

看板Web_Design作者 (憂)時間14年前 (2011/07/13 21:01), 編輯推噓0(0011)
留言11則, 3人參與, 最新討論串1/2 (看更多)
<form id="form1" runat="server"> <div id="ContentDiv"> <input type="button" id="button1" value="add text" /> <input type="submit" id="button2" value="submit" /> <input type="hidden" id="Count" name="Count" value="2" /> <div id="TextBoxDiv"> <input type="text" id="text1" name="text1" value="this is text1" /><br /> </div> <div id="TextValueDiv"> <asp:Label runat="server" ID="Label1"></asp:Label> </div> </div> </form> <script type="text/javascript"> $(function() { $("#button1").click(addTextBox); }); function addTextBox() { var cObject = document.getElementById("Count"); var c = cObject.value; var box = "<input type='text' id='text" + c + "' name='text" + c + "' value='this is text" + c + "' /><br />"; $("#TextBoxDiv > input:text:last").each(function() { $(this).next().after(box); }); var count = Number(c) + 1; cObject.value = count; } 請問一下 為什麼這段程式 一直跳出 必須要有物件的錯誤呢 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.118.7.198

07/13 21:08, , 1F
cObject.value那來的?cbject?
07/13 21:08, 1F
※ 編輯: loveufour 來自: 122.118.7.198 (07/13 21:10)

07/13 21:10, , 2F
不好意思 已修改 但還是一樣會錯誤
07/13 21:10, 2F

07/13 21:20, , 3F
既然都用了jQuery,為何addTextBox不要也乾脆全用下去
07/13 21:20, 3F

07/13 21:26, , 4F
不好意思 因為這一段程式碼是GOOGLE來的 所以我只看得懂
07/13 21:26, 4F

07/13 21:26, , 5F
JS的部分
07/13 21:26, 5F

07/13 21:28, , 6F
你確定你的HTML裡面有上面寫的id物件嗎
07/13 21:28, 6F

07/13 21:30, , 7F
有的
07/13 21:30, 7F
※ 編輯: loveufour 來自: 122.118.7.198 (07/13 21:32)

07/13 21:33, , 8F
我把程式碼完整附上了 請教您一下 謝謝
07/13 21:33, 8F

07/13 21:43, , 9F
http://jsfiddle.net/Wwxhx/ IE、Firefox都是正常work
07/13 21:43, 9F

07/13 21:46, , 10F
謝謝 這就是我要的結果 但是我目前測試不出來
07/13 21:46, 10F

07/13 22:07, , 11F
以解決 因為沒有INCLUDE JQUERY
07/13 22:07, 11F
文章代碼(AID): #1E7PSiKu (Web_Design)
討論串 (同標題文章)
文章代碼(AID): #1E7PSiKu (Web_Design)