js 调用后台,后台调用js

时间:2023-03-08 16:40:19

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="JS/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#btnTJ1").bind("click", function () {
var result = '<% =Print2Web() %>';
alert("执行完毕,请检查一下后台数据有没有打印出来");//结果显然没有打印出来
});

$("#btnTJ2").bind("click", function () {
$("#<%= btnGet.ClientID %>").trigger("click");//效果实现了
});
});
</script>
</head>
<body>
<form runat="server">
<input type="button" value="前台HTML元素调用后台方法" id="btnTJ1" />
<input type="button" value="前台HTML元素调用后台事件" id="btnTJ2" />

<div style=" visibility: hidden">
<asp:Button ID="btnGet" runat="server" Text="辅助前台获取数据" onclick="btnGet_Click" />
</div>
</form>
</body>
</html>

js 压缩图片

<script type="text/javascript">
$(document).ready(function () {
var BH = $('.file-wrap img').height();
function fileChange(e) {
var f = e.files[0];
var _size = f.size;
if (_size > 2048 * 1024) {
mui.alert('选择的图片超过限度,请重新选择!', '', function () { });
return;
}
//console.log(f);
var FR = new FileReader();
FR.readAsDataURL(f);
FR.onload = function (f) {
compressImg(this.result, BH * 2, function (data) {
//$("#newImg").attr("src",data);//保存图片压缩后的64位编码
$('.file-wrap img').attr('src', data);
});
};
}
document.getElementById("image").addEventListener("change", function () {
fileChange(this);
}, false);
function compressImg(imgData, maxHeight, onCompress) {
if (!imgData) { return false };
onCompress = onCompress || function () { };
maxHeight = maxHeight || 100; //默认最大高度1000px
var canvas = document.createElement('canvas');
var img = new Image();
img.src = imgData;

img.onload = function () {
if (img.height > maxHeight) {//按最大高度等比缩放
img.width *= maxHeight / img.height;
img.height = maxHeight;
}
var ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0, img.width, img.height);
onCompress(canvas.toDataURL("image/jpeg"));
//console.log(canvas.toDataURL("image/jpeg"));
$('#IMAGE_URL').val(canvas.toDataURL("image/