在JavaScript中,从以字母开头的字符串(如“test [123]”)解析INT的最佳方法是什么?我需要一些可以用于下面例子的东西。从javascript中的字符串解析Int
我的JS:
$(document).ready(function() {
$(':input').change(function() {
id = parseInt($(this).attr("id")); //fails for the data below
alert(id);
});
}
我生成的HTML:
<select id="attribute[123]">
<!-- various options -->
</select>
<select id="attribute[456]">
<!-- various options -->
</select>
谢谢!
有趣的是,如果有这将无法工作像“1e10”这样的有效float文字 – Triptych 2009-01-16 00:22:28
如果没有全局标志,我认为这完全不起作用。 – Prestaul 2009-01-16 00:40:38