我的投入,像這樣的名稱替換第一個方括號中的數值:的JavaScript的name屬性
<input class="serialize" name="day[0][0]" />
<input class="serialize" name="event[0][0][0][0]" />
我想要做的是更換第一個夾子的字符(天[] [0],事件[] [0] [0] [0])...但是在夾具中的人物可以改變...
這裏是第一代碼草案
jQuery(this).find('.serialize').each(function(index) {
var attr = jQuery(this).attr('name');
attr = attr.replace('regex magic'); // This line is the problem
jQuery(this).attr('name', attr);
});
因爲數組鍵可以改變...這將打破取代 –
你需要只替換第一個'['之後的第一個字符,或者它可以是多個字符,直到關閉']'? –