[英]Call Javascript function using button OnClick event
我有一个按钮
<asp:Button ID="btnfirstnext" TabIndex="1" runat="server" Text="Next" class="action-button" OnClick="btnfirstnext_Click" />
我有 javascript 之类的
<script>
$(function () {
//jQuery time
var current_fs, next_fs, previous_fs; //fieldsets
var left, opacity, scale; //fieldset properties which we will animate
var animating; //flag to prevent quick multi-click glitches
$(".next1").click(function () {
if (animating) return true;
animating = true;
current_fs = $(this).parent();
next_fs = $(this).parent().next();
//activate next step on progressbar using the index of next_fs
$("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
//show the next fieldset
next_fs.show();
//hide the current fieldset with style
current_fs.animate({ opacity: 0 }, {
step: function (now, mx) {
//as the opacity of current_fs reduces to 0 - stored in "now"
//1. scale current_fs down to 80%
scale = 1 - (1 - now) * 0.2;
//2. bring next_fs from the right(50%)
left = (now * 50) + "%";
//3. increase opacity of next_fs to 1 as it moves in
opacity = 1 - now;
current_fs.css({ 'transform': 'scale(' + scale + ')' });
next_fs.css({ 'left': left, 'opacity': opacity });
},
duration: 800,
complete: function () {
current_fs.hide();
animating = false;
},
//this comes from the custom easing plugin
easing: 'easeInOutBack'
// $('btnfirstnext').trigger('click');
});
});
我想在我点击按钮时调用这个 javascript 请帮助我我尝试过像OnClientClick="javascript: return .next1;"
但它不起作用,我也尝试class=".next1 action-button"
和onclicentclick="return false;"
这是工作,但由于其他一些问题,我不想使用它。
更改您的按钮 ID 与点击事件 ID 名称next1
并从按钮中删除OnClick="btnfirstnext_Click"
<asp:Button ID="next1" TabIndex="1" runat="server" Text="Next" class="action-button" />
并如下更改您的函数参数,这将调用此函数
$("#next1").click(function () {
您可以尝试以下解决方案之一:
1) 带功能
<asp:Button TabIndex="1" runat="server" Text="Next" class="action-button" OnClick="javascript:doSomething()" />
<script type="text/javascript">
function doSomething() {
//do something
}
</script>
2) with class(按钮定义中的类名前没有点)
<asp:Button TabIndex="1" runat="server" Text="Next" class="action-button next" />
<script type="text/javascript">
$(".next").click(function() {
//do something
});
</script>
3) 带身份证
<asp:Button ID="next" TabIndex="1" runat="server" Text="Next" class="action-button" />
<script type="text/javascript">
$("#next").click(function() {
//do something
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.