我使用jquery,我有一个textarea,所以当我提交按钮时,我会用换行符分别提醒每个文本.如何拆分换行?
var ks = $('#keywords').val().split("\n");
(function($){
$(document).ready(function(){
$('#data').submit(function(e){
e.preventDefault();
alert(ks[0]);
$.each(ks, function(k){
alert(k);
});
});
});
})(jQuery);
Run Code Online (Sandbox Code Playgroud)
示例输入:
Hello
There
Run Code Online (Sandbox Code Playgroud)
我想要的结果是:
alert(Hello); and
alert(There)
Run Code Online (Sandbox Code Playgroud) 我希望转换数大于5再次变为1-5,例如:
6 become 1
7 become 2
8 become 3
9 become 4
Run Code Online (Sandbox Code Playgroud)
所以,如果我输入数字6-9到我的函数,它将转换为上面的解释.
my_function(6); //will become 1
my_function(7); //will become 2 and so on...
Run Code Online (Sandbox Code Playgroud)