如何在javascript事件中触发jquery函数? [英] How to trigger a jquery function in a javascript event?

查看:77
本文介绍了如何在javascript事件中触发jquery函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是更新的帖子。在我的原始帖子中,我询问了如何触发jQuery事件。我得到了2个解决方案。由于一个未知的原因,我原来的帖子已经消失了。我必须重新发布它。在此更新中,我修改了每个响应的编码。触发jquery函数。但是,我无法得到预期的结果。相关代码如下。如果我点击ht页面上的链接,Outlook会弹出。在此触发事件中,即使触发了jquery函数,Outlook也不会弹出。在此更新中,我希望有人可以指出我应该做些什么来使触发事件像真正的onclick。谢谢。

 <%@     Page    语言  =  C#    AutoEventWireup   =  true    CodeBehind   =  TestEmail.aspx.cs   继承  =  GIS_Webpages.RequestForm.TestEmail   %>  

< !DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd >

< html < span class =code-attribute> xmlns = http://www.w3.org/1999/xhtml >
< head runat = server >
< meta http-equiv = < span class =code-keyword> Content-Type content = text / html; charset = utf-8 / > ;
< script src = // ajax.googleapis .com / ajax / libs / jquery / 1.10.2 / jquery.min.js > < ; / script >

< / head >
< body >
< form id = form1 runat = < span class =code-keyword> server >
< div >

< p style = margin-removed 0px; id =' p1' >
< 输入 id = btn2 名称 = btn2 类型 = 按钮 value = 提交 / >
< a href = class = aaf id < span class =code-keyword> =' a1' > zzzzzzz < / a >
< / p >

< / div >
< / form >

< script type = text / javascript >
$(' 。aaf')。on( 点击 function (){
调试器;
var id_ = $( this )。attr( id);
var href = $( this )。attr( href);
})

function f1(){
debugger ;
document .getElementById(' a1').href = mailto:xxx@myCompany.com?subject = free chocolate& body =嗨!如何你呢?;
$(' #a1')。trigger(' 点击);
}

f1();

< / script >
< / body >
< / html >





我尝试过:



请参阅上面的说明 - 无法触发标记 中的点击事件

解决方案

' 。aaf')。on( 点击 function (){
调试器;
var id_ =


< blockquote>( this )。attr( id);
var href =


this )。 attr( href);
})

function f1(){
debugger ;
document .getElementById(' a1').href = mailto:xxx@myCompany.com?subject = free chocolate& body =嗨!如何你呢?;


This is the updated post. In my original post, I asked to how to trigger a jQuery event. I got 2 solution responses. For an unknown reason, my original post was gone. I have to re-post it. In this update, I revised my coded per one of the response. The jquery function is triggered. However, I could not get my expected result. The related code is below. If I click the link on ht page, Outlook pops out. In this triggered event, Outlook does not pop out even though the jquery function is triggered. In this update, I wish someone can point out what I should do to make the triggered event like a real onclick. Thanks.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestEmail.aspx.cs" Inherits="GIS_Webpages.RequestForm.TestEmail" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
 
</head>
<body>
    <form id="form1"  runat="server">
    <div>
    
        <p style="margin-removed 0px;" id='p1' >
            <input id="btn2" name="btn2" type="button" value="Submit" />
            <a href="#" class="aaf" id='a1'  >zzzzzzz</a>
         </p>
    
    </div>
    </form>

    <script type="text/javascript">
        $('.aaf').on("click", function () {
            debugger;
            var id_ = $(this).attr("id");
            var href = $(this).attr("href");
        })

        function f1() {
            debugger;
            document.getElementById('a1').href = "mailto:xxx@myCompany.com?subject=free chocolate&body=Hi! How are you?";
            $('#a1').trigger('click');
        }

        f1();

    </script>
</body>
</html>



What I have tried:

See the description above - Can't trigger the click event in tag

解决方案

('.aaf').on("click", function () { debugger; var id_ =


(this).attr("id"); var href =


(this).attr("href"); }) function f1() { debugger; document.getElementById('a1').href = "mailto:xxx@myCompany.com?subject=free chocolate&body=Hi! How are you?";


这篇关于如何在javascript事件中触发jquery函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆