我想用jQuery來填寫一些表單的默認值。填寫表單與jQuery
窗體包含在一個具有ID的div中。實際上,每個元素都有一個ID,我只是爲了能夠使用$("#id")
語法快速選擇每一個表格。
這裏是形式:
<div id="panel" style="position: absolute; left: 190px; top: 300px; width: 400px; height: 300px; border: medium groove brown; background: none repeat scroll 0% 0% black; z-index: 100; color: white;"><form id="form_coord_0">
X <input type="text" style="height: 25px; font-size: 10px;" size="2" name="X" id="coordX_0"/>
Y <input type="text" style="height: 25px; font-size: 10px;" size="2" name="Y" id="coordY_0"/>
<input type="button" id="edit_0" value="M"/>
<input type="button" id="remove_0" value="-"/>
<input type="button" id="add_0" value="+"/>
<input type="button" id="go_0" value="go!"/>
<br/>
</div>
我需要設置coordX_0
文本字段一定的價值,讓我們說:123
。
我想我可以做
$("#coordX_0").text.value = 123;
但它似乎並沒有工作。任何提示?
http://api.jquery.com/val,文檔是你的朋友。 – Jasper 2012-01-18 17:06:24
謝謝Jasper,我是jQuery的新手(嗯,即使使用js:D),我甚至不知道val()方法存在。 – nick2k3 2012-01-18 17:23:51
@ nick2k3我在學習jQuery時做的第一件事就是瀏覽API文檔,查看所有可用功能以及如何使用它們的演示。我這樣做是爲了讓我至少有一個框架允許我做的基本概念。例如'.val()'函數可以將一個函數作爲參數,如果你想一次處理多個表單輸入的話,你可以在下面看到我的答案,例如如何執行此操作:http://stackoverflow.com/questions/8914161/8914281#8914281 – Jasper 2012-01-18 17:42:46