我想用:
$( “...”)。动画()
加载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内联代码:
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滚动页面吗?
提前致谢
答案 0 :(得分:2)
为了更加安全,你应该做以下事情:
在你的回调函数中:
$('#element-name').html('string'); // or jQuery(...).html(...)
您可以优化一些代码以使用更多jQuery:
您可以设置元素的innerHTML,而不是使用document.getElementById(&#34; element-name&#34;)。innerHTML =&#39; string&#39;通过使用jQuery:
<div id="some-element" onclick="showtopic('your-attribute')"></div>
您可以编写$(...)而不是jQuery(...),为您节省一些输入:)(在使用jQuery.noConflict()时不要使用)
< / LI>scrollTop: (jQuery(document).height() * 0.9) + 'px'
使用&#39; px&#39;将scrollTop设置为大于零的数字时。
Dim sourceSheet As Worksheet
Set sourceSheet = ActiveSheet
Analysis(sourceSheet)
您似乎并不完全了解jQuery与JavaScript的关系。 JavaScript是一种编程语言。 jQuery是一个用JavaScript编写的库或插件。所以,jQuery内联代码= JavaScript内联代码。