插件很简单,是拿到textarea里的值(这个值应该是多行的),然后拼接为字符串
/**
* Mui Plugin for 接收textarea里的值,按行分割为数组后,通过for循环,加上'连接符'拼接为'字符串'
* 参考:http://www.jb51.net/article/74491.htm
* @version 0.1
* @requires Mui v3.4.1 or later
*
* Copyright (c) 20151221 ZZYY
* 使用方法如下:
* var cc = mui("#textarea1").barCodes();
* console.info(cc);
*
*/
(function( $ ) {
$.fn.barCodes = function(options) {
var defaults = {
'regexSTR': '\n',
'connector': '\^'
};
var settings = $.extend({},defaults, options);
var patt1 = new RegExp("^[ ]+$");
var ids = "";
var self = this[0];
// console.info(self);
//var c = this.val();
var c = self.value ;
var csz = c.split(settings.regexSTR);
for (var i = 0; i < csz.length; i++) {
if (csz[i] == null || csz[i] == "" || patt1.test(csz[i]) ) {
//console.info("NULL");
} else {
ids = ids + settings.connector + csz[i];
//console.info(csz[i]);
}
}
ids = ids.substring(settings.connector.length, ids.length);
return ids;
};
})( mui );
0 个评论
要回复文章请先登录或注册