我正在尝试拆分n个元素的数组(数组元素的数量总是可以分成2个),例如我有一个包含20个元素的数组,现在我能够拆分the first 10 elements and show it但是我没有任何想法如何分割接下来的10个元素,这是我的代码,或多或少地看到我正在尝试做的事情:
var array = "1, 5, 4, 3, 2, 6, 7, 8, 6, 55, 4, 33, 67, 7, 65, 45, 34, 32, 12, 23";
var array1 = [];
var array2 = [];
$(document).ready(function() {
$('#btn').click(function() {
magic();
});
});
function magic() {
var split;
var data = array.split(",");
var total = data.length;
for (var i = 0; i < total / 2; i++) {
array1.push(data[i]);
}
$('#a1').text(array1);
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="btn">Magic!</button> …Run Code Online (Sandbox Code Playgroud)我正在使用带有WebMethod的C#aspx Web表单但是我在尝试使用公共方法调用类时遇到问题,我收到以下错误消息:
非静态字段方法或属性需要对象引用.
这是我的代码示例.
DB_Class
public int Cuenta(User us, int opcion)
{
string sql = "";
int res = 0;
switch (opcion)
{
//Insert
case 1:
sql = "query...";
break;
//Update
case 2:
sql = "";
break;
//Delete
case 3:
sql = "";
break;
}
//More code, using executenonquery etc. there is no problem with that.
return res;
}
Run Code Online (Sandbox Code Playgroud)
ASPX,Webmethod代码
db_Class conn = new db_Class();
[WebMethod]
public static string RegistrarCuenta(int id, string usuario, string nombre, string apellido, string email, string …Run Code Online (Sandbox Code Playgroud)