在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