$.fn.combineInput = function (_config) {
var _config = $.extend({
addStr: ""
});
var td = $(this);
var input = td.find("input");
var inputLength = input.length;
var _temp = [];
var _tempStr = '';
var pack = {
init: function () {
for (var i = 0; i < inputLength; i++) {
_temp[i] = input.eq(i).val();
}
return pack.combine();
},
combine: function () {
_tempStr = _temp.join(_config.addStr);
return _tempStr;
}
};
return pack.init();
}
//拆分字符串填入输入框
$.fn.splitInput = function (value) {
var _temp = [];
for (var i = 0; i < value.length; i = i + 4) {
_temp.push(value.substring(i, i + 4));
}
var td = $(this);
var input = td.find("input");
var inputLength = input.length;
for (i = 0; i < inputLength; i++) {
input.eq(i).val(_temp[i]);
}
return _temp;
}
html
<div id="test">
几个<input>
</div>
引用
$("#test").combineInput()