首頁  >  文章  >  web前端  >  如何判斷jquery物件是input還是select

如何判斷jquery物件是input還是select

coldplay.xixi
coldplay.xixi原創
2020-11-27 14:33:174348瀏覽

判斷jquery物件是input還是select的方法:先開啟html編輯器,新建html檔;然後在【index.html】中的【<script>】標籤中,輸入js程式碼;最後瀏覽器運行【index.html】頁面即可。 </script>

如何判斷jquery物件是input還是select

本教學操作環境:windows7系統、jquery3.2.1版,Dell G3電腦。

判斷jquery物件是input還是select的方法:

1、首先,開啟html編輯器,新建html文件,例如:index.html。

如何判斷jquery物件是input還是select

2、在index.html中的<script></script>標籤中,輸入js程式碼:

if ($(&#39;#a&#39;).is(&#39;input&#39;)) {
$(&#39;body&#39;).append(&#39; is input&#39;);
} else if($(&#39;#a&#39;).is(&#39;select&#39;)) {
$(&#39;body&#39;).append(&#39; is select&#39;);
}

如何判斷jquery物件是input還是select

3、瀏覽器運行index.html頁面,此時會輸出對jquery物件類型的判斷結果。

如何判斷jquery物件是input還是select

相關免費學習推薦:javascript(影片)

#

以上是如何判斷jquery物件是input還是select的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn