来自Jquery循环的Onclick调用

时间:2016-03-23 13:55:37

标签: javascript jquery

是否可以通过onclick命令执行两个命令?我希望第一个图像的onclick命令不仅可以执行到另一个页面的链接,还可以执行mailto命令。我可以用功能吗?如果是这样,onclick如何调用函数以及函数应放在何处?

以下是代码片段:

document.write('<div id="JQCycle1" class="JQslideshow center-JQS" style="width: 180px; height: 150px;">');

document.write('<img src="JQuery-Cycle/set1/image1.jpg" alt="Image 1" width="180" height="150" onclick="javascript:location.href=\'http://bilbowdish.ipage.com/gulfdriveband/index.html\'" style="cursor:pointer;">');
// document.write('<img src="JQuery-Cycle/set1/image1.jpg" alt="Image 1" width="180" height="150" onclick="HMimage1()">');
document.write('<img src="JQuery-Cycle/set1/image2.jpg" alt="Image 2" width="180" height="150" onclick="javascript:location.href=\'mailto:gulfdriveband@gmail.com\'" style="cursor:pointer;">');

document.write('</div>');

1 个答案:

答案 0 :(得分:0)

使用Javascript / Jquery的

function change() {
    var url = "https://www.google.com";
    window.open(url);
    window.location.href = "mailto:address@dmail.com";
}

$(document).ready(function() {

    $('#img1').on("click", function() {
        change();
    });
})

HTML:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js">    </script>

<img id="img1" src="" height="50px" width="50px" style="background-color:red">

window.open会打开一个新标签并更改为新页面。 window.location.href将更改当前页面,并在其中放置mailto:拉出电子邮箱。