点击复制

<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<script src="<%=request.getContextPath()%>/js/My97DatePicker/WdatePicker.js" type="text/javascript" charset="UTF-8"></script>
<script type="text/javascript">
	function copyToClipboard() {  
		var txt = $("#aflink").val();
	     if(window.clipboardData) {   
	             window.clipboardData.clearData();   
	             window.clipboardData.setData("Text", txt);   
	     } else if(navigator.userAgent.indexOf("Opera") != -1) {   
	          window.location = txt;   
	     } else if (window.netscape) {   
	          try {   
	               netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");   
	          } catch (e) {   
	               alert("您的浏览器设置不允许快捷拷贝,请直接复制页面里的链接");      
	          }   
	          var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);   
	          if (!clip)   
	               return;   
	          var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);   
	          if (!trans)   
	               return;   
	          trans.addDataFlavor('text/unicode');   
	          var str = new Object();   
	          var len = new Object();   
	          var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);   
	          var copytext = txt;   
	          str.data = copytext;   
	          trans.setTransferData("text/unicode",str,copytext.length*2);   
	          var clipid = Components.interfaces.nsIClipboard;   
	          if (!clip)   
	               return false;   
	          clip.setData(trans,null,clipid.kGlobalClipboard);   
	          alert("复制成功!")   
	     }   
	}
</script>

<!-- 金币收集 -->
<div class="top_title"><span class="fr fontsize12">积累金币,获得更多荣誉,可直接换取游戏币</span><h3>金币收集</h3></div>
<div class="level_c">
	<div class="collect_record clearfix">
		<div class="collect_tit alignright">您的账户目前积分币数</div>
		<div class="collect_tit"><s:property value="#request.userInfo.earnedRewards"/></div>
		<div class="collect_tit"><a class="und_line">查看积分历史</a></div>
		<div class="collect_tit"><span class="btn"><a class="release" href="/account/gradeRule.do">金币收集规则</a></span></div>
	</div>
	<div class="collect_record clearfix">
		<div class="collect_tit alignright">兑换游戏币</div>
		<div class="collect_tit"><s:property value="#request.userInfo.earnedRewards"/></div>
		<div class="collect_tit"><span class="btn2"><a class="release">兑 换</a></span></div>
		<div class="collect_tit"><a class="und_line">兑换记录</a></div>
	</div>
</div>
<div class="collect_c">
	<div class="collect_step">
		<p>1.完成新手任务获得1个金币
			<s:if test="#request.taskType == 1"> 
			<b>(未完成)</b>
			</s:if>
			<s:else>
			<b>(已完成)</b>	
			</s:else>
		</p>
	</div>
	<div class="collect_step">
	<p>2.推广链接</p>
	<div class="collect_copy">
		<input type="text" id="aflink" name="aflink" value="http://www.108pub.com/?af=<s:property value="#request.userInfo.userId"/>"/>
		<div class="btn"><a class="release" onclick="javascript:copyToClipboard();">点击复制</a></div>
	</div>
	<div class="clears"></div>
	
	</div>
</div>

你可能感兴趣的:(JavaScript)