在javascript中,从以字母开头的字符串(例如"test [123]")解析INT的最佳方法是什么?我需要一些适合下面例子的东西.
我的JS:
$(document).ready(function() {
$(':input').change( function() {
id = parseInt($(this).attr("id")); //fails for the data below
alert(id);
});
}
Run Code Online (Sandbox Code Playgroud)
我生成的HTML:
<select id="attribute[123]">
<!-- various options -->
</select>
<select id="attribute[456]">
<!-- various options -->
</select>
Run Code Online (Sandbox Code Playgroud)
谢谢!