我有提交按钮的网站,可以点击,但android(chrome)上没有动作。在PC chrome上它工作正常。不知道问题出在哪里......
<input style="display:none" type="submit" class="inline-right vytvorplakat" value="Publikovat plakát" onclick="capture();" />
function capture() {
$('#target2').html2canvas({
onrendered: function (canvas) {
//Set hidden field's value to image data (base-64 string)
$('#img_val').val(canvas.toDataURL("image/png"));
//Submit the form manually
document.getElementById("myForm").submit();
}
});
}
我试过这个:(正如Navjot Singh建议的那样)但仍然存在同样的问题,只适用于桌面
<input style="display:none" type="submit" class="inline-right vytvorplakat" value="Publikovat plakát" <a href="javascript:capture()">
答案 0 :(得分:1)
onclick
,它可能会在现代浏览器或设备上出现意外行为。尝试为此单击绑定事件侦听器,如下所示:
document.getElementsByClassName("vytvorplakat")[0].addEventListener("click", capture);
<强>更新强>:
示范片段:
function capture() {
console.log('test');
//here goes your html2canvas code
}
document.getElementsByClassName("vytvorplakat")[0].addEventListener("click", capture);
<input type="submit" class="inline-right vytvorplakat" value="Publikovat plakát" />
答案 1 :(得分:0)
尝试在JS中绑定事件来解决这个问题:)
$(".vytvorplakat").on("click" ,capture );
我认为这将解决您的问题 将ID设置为此按钮并在此ID中绑定事件 因为Onclick不支持某些浏览器
<强> HTML 强>
<input id="testing" type="submit" class="inline-right vytvorplakat" value="Publikovat plakát" />
<强> JS 强>
$("#testing").on("click" ,capture );
function capture() {
//remove this alert
alert("Welcom from capture");
$('#target2').html2canvas({
onrendered: function(canvas) {
//Set hidden field's value to image data (base-64 string)
$('#img_val').val(canvas.toDataURL("image/png"));
//Submit the form manually
document.getElementById("myForm").submit();
}
});
}