网页按钮发送信息给服务器,选中网页内容弹出按钮点击发送选中内容到服务器...

效果:在网页中选中一段内容后,自动弹出一个按钮,点击按钮可以将选中的内容回发到服务器。

实现方法:用javascript添加document.onmouseup事件,用range API判断是否选中内容,选中内容则弹出按钮,给按钮绑定点击事件,点击后将选中的内容使用ajax发送到服务器端。

选中网页内容弹出按钮点击发送选中内容到服务器源代码如下

#btnSend{position:absolute;display:none;}

var selectedText;

function ajaxSend(){alert(selectedText)

$('#btnSend').attr('disabled',true)

$.ajax({url:'xxxx.ashx',type:'POST',data:{s:selectedText},complete:function(xhr){

alert('ajax请求完毕,服务器返回内容:'+xhr.responseText);

$('#btnSend').hide();

}});

}

document.οnmοusedοwn=function(){selectedText=false;}

document.οnmοuseup=function(e){

e=e||window.event;

selectedText=window.getSelection?window.getSelection().toString():document.selection?document.selection.createRange().text:false;

if(selectedText){

//判断页面是否有滚动,有的话还得加上滚动的距离,要不按钮定位不准

var sl=Math.max(document.documentElement.scrollLeft,document.body.scrollLeft),

st=Math.max(document.documentElement.scrollTop,document.body.scrollTop);

$('#btnSend').css({left:e.clientX+sl,top:e.clientY+st}).show().attr('disabled',false);

}

else $('#btnSend').hide();

}

效果:在网页中选中一段内容后,自动弹出一个按钮,点击按钮可以将选中的内容回发到服务器。

实现方法:用javascript添加document.onmouseup事件,用range API判断是否选中内容,选中内容则弹出按钮,给按钮绑定点击事件,点击后将选中的内容使用ajax发送到服务器端。

选中网页内容弹出按钮点击发送选中内容到服务器源代码如下

实现方法:用javascript添加document.onmouseup事件,用range API判断是否选中内容,选中内容则弹出按钮,给按钮绑定点击事件,点击后将选中的内容使用ajax发送到服务器端。

选中网页内容弹出按钮点击发送选中内容到服务器源代码如下

xxxx.ashx

string s=context.Request.Form["s"];

context.Response.Write(s+"--"+DateTime.Now);

加支付宝好友偷能量挖...

2015-5-3Web开发网

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值