如何在javascript OnClick中使用jQuery click函数

如何在javascript OnClick中使用jQuery click函数,javascript,jquery,animation,scroll,onclick,Javascript,Jquery,Animation,Scroll,Onclick,我想使用: $(“…”).animate() 通过加载onClickJavaScript Ajax。但这也有一些问题: 我尝试像这样使用jQuery: function Ajaxrequest(){ var xmlHttp;try{xmlHttp=new XMLHttpRequest();return xmlHttp;} catch (e){ try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); return x

我想使用:

$(“…”).animate()

通过加载
onClick
JavaScript Ajax。但这也有一些问题:

我尝试像这样使用jQuery:

function Ajaxrequest(){
var xmlHttp;try{xmlHttp=new XMLHttpRequest();return xmlHttp;}
    catch (e){
        try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        return xmlHttp;
    }
    catch (e){
        try{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        return xmlHttp;}
    catch (e){
        alert("Browser Not support Ajax");
        return false;}
    }
}

function showtopic(str) {
    $("html,body").animate({
        scrollTop: jQuery(document).height()
    }, 2000);
    var xmlHttp = Ajaxrequest();
    var issolve = "<a href=\'#topic\' title=\'دادن امتیاز\' class=\"fade\" id=\'solved\' onclick=\"showbest('faq.php?like=2lkha96slh','solved' , 'notsolved')\">+1 مشکلم حل شد</a><a href=\"http://my-bb.ir\" id=\"notsolved\" class=\"fade\" title=\"پرسیدن سوال\" target=\"_blank\" >نبابا حل نشد ! میخوام سوال بپرسم</a></li><br/><br/>";
    if (str == "") {
        document.getElementById("showtopic").innerHTML = "";
        return;
    }
    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState > 0 && xmlHttp.readyState < 4) {
            document.getElementById("tftopic").innerHTML = loadingmessage;
        }
        if (xmlHttp.readyState == 4) {
            document.getElementById("showtopic").innerHTML = xmlHttp.responseText;
            document.getElementById("issolved").innerHTML = issolve;
        }
    }
    xmlHttp.open("GET", str, true);
    xmlHttp.send();
}
jQuery('.go-bott').click(function () {
      $('html,body').animate({
          scrollTop: (jQuery(document).height() * 0.9)
      }, 2000);
      return false;
  });
在JavaScript
onClick
旁边使用它,但是Ajax不允许jQuery运行(此代码将在一个简单的类上运行)

如何使用jQuery滚动键单击
onClick
JavaScript-Ajax或使用JavaScript滚动页面

提前感谢

1。有些事情 为了更加安全,您应该做以下事情:

  • 在回调函数中:

    if (xmlHttp.readyState > 0 && xmlHttp.readyState < 4) {
        document.getElementById("tftopic").innerHTML = loadingmessage;
    } else if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
        document.getElementById("showtopic").innerHTML = xmlHttp.responseText;
        document.getElementById("issolved").innerHTML = issolve;
    } else {
        // do your error handling here
    }
    
  • 您可以编写$(…)而不是jQuery(…),这样可以节省一些输入:)(在使用jQuery.noConflict()时不要使用)


2.onclick


3.卷轴 将scrollTop动画设置为大于零的数字时,请使用“px”。


4.让我说清楚
您似乎不太了解jQuery与JavaScript的关系。JavaScript是一种编程语言。jQuery是一个用JavaScript编写的库或插件。因此,jQuery内联代码=JavaScript内联代码。

你知道jQuery是JavaScript吗?请修正你的格式,很难理解当前格式的代码,你在哪里调用showtopic(..)?我编辑我的帖子,实际上我有一个Ajaxrequest()功能到您的第一点。thnx很多让我试试亲爱的stefan我理解您的提示stefan但我的代码仍然没有滚动!××! 我把它们放在这里@mehdi,甚至可以用你的功能滚动:!!!然后我想这是因为如果ajax我的代码不起作用!您的代码没有ajax,只需使用函数加载滚动。。。这是页面。@mehdi抱歉,我在页面上找不到调用showtopic的元素,我只能找到showbest和showlevel。它在哪里?
$('#element-name').html('string'); // or jQuery(...).html(...)
scrollTop: (jQuery(document).height() * 0.9) + 'px'