我有这个功能,我用onClick调用它。谷歌Chrome(Windows)正在运行,但在Android Chrome上却没有。如何让它在Android Chrome中使用ontouch?
谢谢!
function copyCupon(cupon, link) {
var copyText = document.createElement("input");
document.body.appendChild(copyText);
copyText.setAttribute("id", "copyTextId");
copyText.setAttribute('value', cupon);
copyText.select();
document.execCommand("copy");
document.body.removeChild(copyText);
alert("Cuponul " + "'" + copyText.value + "'" + " a fost copiat. Spor la cumparaturi! :)");
window.open(link);
}
<button onclick="copyCupon('test to copy', 'http://www.google.ro')">Copy coupon</button>
答案 0 :(得分:1)
试试这个:
pointer
添加到按钮样式touchstart
:$(&#39;#whatever&#39;)。on(&#39; touchstart click&#39;,function(){/ * your code * /}};
答案 1 :(得分:0)
这里是使用jQuery的小提琴。
$('#btn').on('touchstart click', function() {
var cupon = $('#btn').attr('val1');
var link = $('#btn').attr('val2');
var copyText = document.createElement("input");
document.body.appendChild(copyText);
copyText.setAttribute("id", "copyTextId");
copyText.setAttribute('value', cupon);
copyText.select();
document.execCommand("copy");
document.body.removeChild(copyText);
alert("Cuponul " + "'" + copyText.value + "'" + " a fost copiat. Spor la cumparaturi! :)");
window.open(link);
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id='btn' val1='test to copy' val2='http://www.google.ro'>Copy coupon</button>
&#13;
答案 2 :(得分:0)
添加光标:指针;到 css 对我有用,但无法提供任何解释原因。
function do_something() {
alert('It works now!')
}
.button {
cursor: pointer;
}
<button class='button' onclick='do_something()'>Click</button>
.button {
cursor: pointer;
}