ถามหน่อยครับ เรื่อง autocomplete
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา ถามหน่อยครับ เรื่อง autocomplete
ถามหน่อยครับ เรื่อง autocomplete
Copy
ผมได้ใช้ Auto Complete ในการทำการค้นหาในฐานข้อมูล แต่ มันใช้งานได้แค่อันเดียว อ่ะครับ คืออันแรก ถ้าผมกดเพิ่ม Element มันจะเพิ่มใช่ไหมครับแต่ element ที่เพิ่มมามันไม่ตอบสนองกับ auto complete อ่ะครับทั้งที่ ชื่อ และ class ก็เหมือนกับอันแรก อ่ะครับ ผมควรทำอย่างไรดี <code><span class="tag"><script></span><span class="pln"> $</span><span class="pun">(</span><span class="pln">document</span><span class="pun">).</span><span class="pln">ready</span><span class="pun">(</span><span class="kwd">function</span><span class="pun">(){</span><span class="pln"> $</span><span class="pun">(</span><span class="str">"#addCF"</span><span class="pun">).</span><span class="pln">click</span><span class="pun">(</span><span class="kwd">function</span><span class="pun">(){</span><span class="pln"> $</span><span class="pun">(</span><span class="str">"#customFields"</span><span class="pun">).</span><span class="pln">append</span><span class="pun">(</span><span class="str">'<tr valign="top"><th scope="row"><label for="customFieldName">Custom Field</label></th><td><input type="text" class="med" name="customFieldName[]" value="" placeholder="รายชื่อยา" /> <input type="text" class="code" name="customFieldValue[]" value="" placeholder="Input Value" /> <a href="javascript:void(0);" id="remCF">Remove</a></td></tr>'</span><span class="pun">);</span><span class="pln"> </span><span class="pun">});</span><span class="pln"> $</span><span class="pun">(</span><span class="str">"#customFields"</span><span class="pun">).</span><span class="pln">on</span><span class="pun">(</span><span class="str">'click'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'#remCF'</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(){</span><span class="pln"> $</span><span class="pun">(</span><span class="kwd">this</span><span class="pun">).</span><span class="pln">parent</span><span class="pun">().</span><span class="pln">parent</span><span class="pun">().</span><span class="pln">remove</span><span class="pun">();</span><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="pun">);</span><span class="pln"> </span><span class="pun">});</span><span class="pln"> </span><span class="tag"></script></span><span class="pln"> </span><span class="tag"><script></span><span class="com">//auto complete Code</span><span class="pln"> $</span><span class="pun">(</span><span class="kwd">function</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> $</span><span class="pun">(</span><span class="str">'.med'</span><span class="pun">).</span><span class="pln">autocomplete</span><span class="pun">({</span><span class="pln"> source</span><span class="pun">:</span><span class="pln"> </span><span class="str">"show.php"</span><span class="pun">,</span><span class="pln">minLength</span><span class="pun">:</span><span class="pln"> </span><span class="lit">2</span><span class="pun">,</span><span class="pln"> select</span><span class="pun">:</span><span class="kwd">function</span><span class="pun">(</span><span class="pln"> event</span><span class="pun">,</span><span class="pln"> ui </span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> $</span><span class="pun">(</span><span class="str">'#name'</span><span class="pun">).</span><span class="pln">val</span><span class="pun">(</span><span class="pln">ui</span><span class="pun">.</span><span class="pln">item</span><span class="pun">.</span><span class="pln">name</span><span class="pun">);</span><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="pun">});</span><span class="pln"> </span><span class="pun">});</span><span class="pln"> </span><span class="tag"></script></span><span class="pln"> </span><span class="tag"><table</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"form-table"</span><span class="pln"> </span><span class="atn">id</span><span class="pun">=</span><span class="atv">"customFields"</span><span class="tag">></span><span class="pln"> </span><span class="tag"><div</span><span class="pln"> </span><span class="atn">id</span><span class="pun">=</span><span class="atv">"name"</span><span class="pln"> </span><span class="tag">></div></span><span class="pln"> </span><span class="tag"><tr</span><span class="pln"> </span><span class="atn">valign</span><span class="pun">=</span><span class="atv">"top"</span><span class="tag">></span><span class="pln"> </span><span class="tag"><th</span><span class="pln"> </span><span class="atn">scope</span><span class="pun">=</span><span class="atv">"row"</span><span class="tag">><label</span><span class="pln"> </span><span class="atn">for</span><span class="pun">=</span><span class="atv">"customFieldName"</span><span class="tag">></span><span class="pln">Custom Field</span><span class="tag"></label></th></span><span class="pln"> </span><span class="tag"><td></span><span class="pln"> </span><span class="tag"><input</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"text"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"med"</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"customFieldName[]"</span><span class="pln"> </span><span class="atn">value</span><span class="pun">=</span><span class="atv">""</span><span class="pln"> </span><span class="atn">placeholder</span><span class="pun">=</span><span class="atv">"รายชื่อยา"</span><span class="pln"> </span><span class="tag">/></span><span class="pln"> </span><span class="tag"><input</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"text"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"code"</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"customFieldValue[]"</span><span class="pln"> </span><span class="atn">value</span><span class="pun">=</span><span class="atv">""</span><span class="pln"> </span><span class="atn">placeholder</span><span class="pun">=</span><span class="atv">"จำนวน"</span><span class="pln"> </span><span class="tag">/></span><span class="pln"> </span><span class="tag"><a</span><span class="pln"> </span><span class="atn">href</span><span class="pun">=</span><span class="atv">"javascript:void(0);"</span><span class="pln"> </span><span class="atn">id</span><span class="pun">=</span><span class="atv">"addCF"</span><span class="tag">></span><span class="pln">ADD</span><span class="tag"></a></span><span class="pln"> </span><span class="tag"></td></span><span class="pln"> </span><span class="tag"></tr></span><span class="pln"> </span><span class="tag"></table></span></code> http://jsfiddle.net/earc4436/3/ <<< อันนี้เป็น Interface นะครับ เพื่อใครไม่เข้าใจ แต่ยังไม่ใส่ Autocomplete นะครับ
Count
07-10-2014
10:56:47
คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา
โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ