Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何选择第一个字符 html DOM。我试图 $('#pcode')[0];获取第一个字符,但是当我尝试打印它时它没有给出第一个值它的打印[object HTMLInputElement] 如何使用 jquery 选择 HTML DOM 第一个字符
$('#pcode')[0];
[object HTMLInputElement]
如果我对您的理解正确,那么您在 ID 为“pcode”的元素中有一些文本,并且您想要第一个字符。如果是这样,那么您需要执行以下操作:
$("#pcode").val().charAt(0);
你只是用
您需要提取与对象关联的值
$('#pcode').val()[0];