本文介绍了获得一个字符串第一个字母。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在尝试创建一个在Opera 7.2,Explorer 6.0和 Mozilla 1.4中工作的网站。 我有代码: var imgs = document.getElementsByTagName(" img"); alert(imgs [1] .id); imgs [1]的id是a10。用Opera,Explorer和 Mozilla打开一个窗口,文本为a10。我写的时候: var imgs = document.getElementsByTagName(" img"); alert(imgs [1] .id [0]); 在Mozilla中打开一个窗口,其中包含文本a。但在另外两个 的文本中,未定义。 是否有人知道是否有办法访问 字符串(在我的情况下是包含id名称的字符串)和Explorer, Mozilla和Opera ?? 感谢您将来的反馈。 - Sergio del Amo。 Hi,I am trying to create a web site to work in Opera 7.2, Explorer 6.0 andMozilla 1.4.I have the code: var imgs= document.getElementsByTagName("img");alert(imgs[1].id); The id of imgs[1] is a10. A window is open with Opera, Explorer andMozilla with the text "a10". When i write: var imgs= document.getElementsByTagName("img");alert(imgs[1].id[0]); A window is open in Mozilla with the text "a". But in the other two withthe text "undefined". Does anybody knows if there is a way to acces the first letter of astring(in my case the string which contains the id name) with Explorer,Mozilla and Opera??.Thanks for your future feedback. --Sergio del Amo. 推荐答案 string.charAt(0) 或 string.substring(0,1) 或 string。 substr(0,1) / L - Lasse Reichstein Nielsen - lr*@hotpop.com DHTML死亡颜色:< URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html> ''没有判断的信仰只会降低精神神圣。'' string.charAt(0)orstring.substring(0,1)orstring.substr(0,1) /L--Lasse Reichstein Nielsen - lr*@hotpop.comDHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>''Faith without judgement merely degrades the spirit divine.'' string.charAt( 0)或 string.substring(0,1)或 string.substr(0,1) string.charAt(0)or string.substring(0,1)or string.substr(0,1) 和引用的问题:那些访问第一个字符, 假设有一个。 S ='''123go'' OK = /([az])/i.test(S) RESULT = RegExp。 And for the question as quoted : those access the first character,assuming that there is one. S = ''123go''OK = /([a-z])/i.test(S)RESULT = RegExp. 这篇关于获得一个字符串第一个字母。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 04:16