JS触发按钮事件
前台代码:
<asp:button id="btnsavebattery" runat="server" text="保存" onclick="btnsavebattery_click" />
js代码:
document.getelementbyid('<%=btnsavebattery.clientid%>').click();
或
$("#pagebody_btnsavebattery").click();
如果在前台界面的文本框的个数时可变的,且回车后跳转到另一文本框 代码如下:
<script>
var index = 1;
$(function () {
$(":text:eq("+index+")").focus();
$(":text").keydown(function (e) {
if (e.which == 13) {
if (index == 1) {
var dh = $(".dh");//给文本框定义一个class
var obj = dh[0].value;
if (obj != '') {
e.preventdefault();
index++;
$(":text:eq(" + index + ")").focus();
}
else {
e.preventdefault();
// index = 0;
$(":text:eq(0)").focus();
}
}
else if (index == 2) {
debugger //调试 后期需屏蔽
e.preventdefault();
var sn = $(".sn");
if (sn[index - 2].value != '')
{
index++;
$(":text:eq(" + index + ")").focus();
}
}
else {
e.preventdefault();
var sn = $(".sn");
if (sn[index - 2].value != '') {
var i = 0;
for (i = 0; i < index - 2; i++) {
var obj = sn[i].value;
var last = sn[index - 2].value;
if (obj == last) {
sn[index - 2].value = '';
$(":text:eq(" + index + ")").focus();
break;
}
}
if (i == index - 2) {
index++;
$(":text:eq(" + index + ")").focus();
}
debugger
var max = $(".maxnum");
var obj = max[0].value;
if (obj == index - 2) {
//document.getelementbyid('<%=btnsavebattery.clientid%>').click();
$("#pagebody_btnsavebattery").click();
}
}
}
}
})
})
</script>