在c#中从Button Click事件调用jQuery函数
本文关键字:调用 jQuery 函数 事件 Click 中从 Button | 更新日期: 2023-09-27 18:11:25
我试图在不使用Updatepanel的情况下将裁剪的图像加载到asp:image中。但问题是,它显示图像,但它需要加载$('.image-cropper')。each(linkUp);函数,该函数存在于jQuery(window).load()中,用于启动裁剪过程。但是使用RegisterClientScriptBlock方法,它不会触发该函数。注意:$ (' .image-cropper ') . each(连接);只有在用新映像更新映像之后才应该启动。谁能告诉我错误在哪里?
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ImageResizer;
using System.Text;
public partial class Advanced : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
ScriptManager1.RegisterAsyncPostBackControl(Button1);
if(!IsPostBack)
Image1.ImageUrl = "fountain-small.jpg?width=300";
if (Page.IsPostBack && !string.IsNullOrEmpty(img1.Value))
ImageBuilder.Current.Build("~/"+ImageResizer.Util.PathUtils.RemoveQueryString(img1.Value), "~/cropped.jpg", new ResizeSettings(img1.Value));
}
protected void Button1_Click(object sender, EventArgs e)
{
Image1.ImageUrl = "cropped.jpg?width=300";
UpdatePanel1.Update();
string key = "executeCropScript";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), key, "<script
type='"text/javascript'">jQuery(window).load();</script>", false);
}
}
use add attribute property .
如
Button1.Attributes.Add("onclick", "return:javascript functionname()");
你可以试试这样做…
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
$("button:first").click(function () {
update($("span:first"));
});
$("button:last").click(function () {
$("button:first").trigger('click');
update($("span:last"));
});
function update(j) {
var n = parseInt(j.text(), 10);
j.text(n + 1);
}
});
</script>
<style>
button { margin:10px; }
div { color:blue; font-weight:bold; }
span { color:red; }
</style>
</head>
<body>
<button>Button #1</button>
<button>Button #2</button>
<div><span>0</span> button #1 clicks.</div>
<div><span>0</span> button #2 clicks.</div>
</body>
</html>