通过ajax获取的数据,如何让其它js能执行? $(document).on("hover","li.caption",function () { $(".cover", this).stop().animate({ top: '0px' }, { queue: false, duration: 160 }); }, function () { $(".cover", this).stop().animate({ top: '-307px' }, { queue: false, duration: 160 }); }); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 hover 改成 mouseoverfunction getcityData(id, showul) { var sql = "id="+id; $.ajax({ type: "get", dataType: "html", url: '/Ashx/act.ashx', data: sql, success: function (data) { $("#" + showul).html(data) }, error: function (data) { alert("页面提交失败,请重新提交."); return false; } }); } $(document).ready(function () { getcityData(53, 'showjujiao'); getcityData(54, 'showtese'); getcityData(55, 'showlvyou'); }); $(document).on("mouseover", "li.caption", function () { $(".cover", this).stop().animate({ top: '0px' }, { queue: false, duration: 160 }); }, function () { $(".cover", this).stop().animate({ top: '-307px' }, { queue: false, duration: 160 }); });=================谢谢回复,可这样的代码也执行不了。是哪里写错了? $(document).on("mouseover", "li.caption", function () { $(".cover", this).stop().animate({ top: '0px' }, { queue: false, duration: 160 }); }); $(document).on("mouseleave", "li.caption", function () { $(".cover", this).stop().animate({ top: '-307px' }, { queue: false, duration: 160 }); }); jquery 的ajax把<script scr='x'></script>封装好了。// Install script dataTypejQuery.ajaxSetup({ accepts: { script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript" }, contents: { script: /(?:java|ecma)script/ }, converters: { "text script": function( text ) { jQuery.globalEval( text ); return text; } }});// Handle cache's special case and globaljQuery.ajaxPrefilter( "script", function( s ) { if ( s.cache === undefined ) { s.cache = false; } if ( s.crossDomain ) { s.type = "GET"; s.global = false; }});// Bind script tag hack transportjQuery.ajaxTransport( "script", function(s) { // This transport only deals with cross domain requests if ( s.crossDomain ) { var script, head = document.head || jQuery("head")[0] || document.documentElement; return { send: function( _, callback ) { script = document.createElement("script"); script.async = true; if ( s.scriptCharset ) { script.charset = s.scriptCharset; } script.src = s.url; // Attach handlers for all browsers script.onload = script.onreadystatechange = function( _, isAbort ) { if ( isAbort || !script.readyState || /loaded|complete/.test( script.readyState ) ) { // Handle memory leak in IE script.onload = script.onreadystatechange = null; // Remove the script if ( script.parentNode ) { script.parentNode.removeChild( script ); } // Dereference the script script = null; // Callback if not abort if ( !isAbort ) { callback( 200, "success" ); } } }; // Circumvent IE6 bugs with base elements (#2709 and #4378) by prepending // Use native DOM manipulation to avoid our domManip AJAX trickery head.insertBefore( script, head.firstChild ); }, abort: function() { if ( script ) { script.onload( undefined, true ); } } }; }});var oldCallbacks = [], rjsonp = /(=)\?(?=&|$)|\?\?/;// Default jsonp settingsjQuery.ajaxSetup({ jsonp: "callback", jsonpCallback: function() { var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( ajax_nonce++ ) ); this[ callback ] = true; return callback; }});// Detect, normalize options and install callbacks for jsonp requestsjQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { var callbackName, overwritten, responseContainer, jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ? "url" : typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data" ); // Handle iff the expected data type is "jsonp" or we have a parameter to set if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) { // Get callback name, remembering preexisting value associated with it callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ? s.jsonpCallback() : s.jsonpCallback; // Insert callback into url or form data if ( jsonProp ) { s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName ); } else if ( s.jsonp !== false ) { s.url += ( ajax_rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName; } // Use data converter to retrieve json after script execution s.converters["script json"] = function() { if ( !responseContainer ) { jQuery.error( callbackName + " was not called" ); } return responseContainer[ 0 ]; }; // force json dataType s.dataTypes[ 0 ] = "json"; // Install callback overwritten = window[ callbackName ]; window[ callbackName ] = function() { responseContainer = arguments; }; // Clean-up function (fires after converters) jqXHR.always(function() { // Restore preexisting value window[ callbackName ] = overwritten; // Save back as free if ( s[ callbackName ] ) { // make sure that re-using the options doesn't screw things around s.jsonpCallback = originalSettings.jsonpCallback; // save the callback name for future use oldCallbacks.push( callbackName ); } // Call if it was a function and we have a response if ( responseContainer && jQuery.isFunction( overwritten ) ) { overwritten( responseContainer[ 0 ] ); } responseContainer = overwritten = undefined; }); // Delegate to script return "script"; }}); 你可以试试这样$('li.caption').live("hover",function () { $(".cover", this).stop().animate({ top: '0px' }, { queue: false, duration: 160 }); }, function () { $(".cover", this).stop().animate({ top: '-307px' }, { queue: false, duration: 160 });或者你设置你的$.ajax({ type: "get", dataType: "html", url: '/Ashx/act.ashx', data: sql, async:flase,//设置为同步请求,让这段ajax 执行完毕再在执行别的操作 success: function (data) { $("#" + showul).html(data) },}); 查询;下拉框选按'姓名'查询,名为searchkey的text显示'请输入姓名'?帖有代码 JAVASCRIPT date问题。在线给分 页面滚动.会的请进.本人在线等 ■■■■■■■■■■■■ 如何写“选择textarea第X行到第Y行”的函数? 求教一个javascript JQ遍历计算功能问题急 javascript可以互相嵌套吗?? 如何才能不提交? 如何通过多选框控制大类的搜索嘛? 【简单】比较两个JSON对象,将ID属性添加到第二个JSON对象 jquery为基的编辑器开发问题。 请教JQUERY如何实现这样效果
var sql = "id="+id;
$.ajax({
type: "get",
dataType: "html",
url: '/Ashx/act.ashx',
data: sql,
success: function (data) {
$("#" + showul).html(data)
},
error: function (data) {
alert("页面提交失败,请重新提交.");
return false;
}
});
} $(document).ready(function () {
getcityData(53, 'showjujiao');
getcityData(54, 'showtese');
getcityData(55, 'showlvyou');
}); $(document).on("mouseover", "li.caption", function () {
$(".cover", this).stop().animate({ top: '0px' }, { queue: false, duration: 160 });
}, function () {
$(".cover", this).stop().animate({ top: '-307px' }, { queue: false, duration: 160 });
});=================
谢谢回复,可这样的代码也执行不了。是哪里写错了?
$(document).on("mouseover", "li.caption", function () {
$(".cover", this).stop().animate({ top: '0px' }, { queue: false, duration: 160 });
});
$(document).on("mouseleave", "li.caption", function () {
$(".cover", this).stop().animate({ top: '-307px' }, { queue: false, duration: 160 });
});
<script scr='x'></script>封装好了。
// Install script dataType
jQuery.ajaxSetup({
accepts: {
script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
},
contents: {
script: /(?:java|ecma)script/
},
converters: {
"text script": function( text ) {
jQuery.globalEval( text );
return text;
}
}
});// Handle cache's special case and global
jQuery.ajaxPrefilter( "script", function( s ) {
if ( s.cache === undefined ) {
s.cache = false;
}
if ( s.crossDomain ) {
s.type = "GET";
s.global = false;
}
});// Bind script tag hack transport
jQuery.ajaxTransport( "script", function(s) { // This transport only deals with cross domain requests
if ( s.crossDomain ) { var script,
head = document.head || jQuery("head")[0] || document.documentElement; return { send: function( _, callback ) { script = document.createElement("script"); script.async = true; if ( s.scriptCharset ) {
script.charset = s.scriptCharset;
} script.src = s.url; // Attach handlers for all browsers
script.onload = script.onreadystatechange = function( _, isAbort ) { if ( isAbort || !script.readyState || /loaded|complete/.test( script.readyState ) ) { // Handle memory leak in IE
script.onload = script.onreadystatechange = null; // Remove the script
if ( script.parentNode ) {
script.parentNode.removeChild( script );
} // Dereference the script
script = null; // Callback if not abort
if ( !isAbort ) {
callback( 200, "success" );
}
}
}; // Circumvent IE6 bugs with base elements (#2709 and #4378) by prepending
// Use native DOM manipulation to avoid our domManip AJAX trickery
head.insertBefore( script, head.firstChild );
}, abort: function() {
if ( script ) {
script.onload( undefined, true );
}
}
};
}
});
var oldCallbacks = [],
rjsonp = /(=)\?(?=&|$)|\?\?/;// Default jsonp settings
jQuery.ajaxSetup({
jsonp: "callback",
jsonpCallback: function() {
var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( ajax_nonce++ ) );
this[ callback ] = true;
return callback;
}
});// Detect, normalize options and install callbacks for jsonp requests
jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { var callbackName, overwritten, responseContainer,
jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
"url" :
typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data"
); // Handle iff the expected data type is "jsonp" or we have a parameter to set
if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) { // Get callback name, remembering preexisting value associated with it
callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
s.jsonpCallback() :
s.jsonpCallback; // Insert callback into url or form data
if ( jsonProp ) {
s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
} else if ( s.jsonp !== false ) {
s.url += ( ajax_rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
} // Use data converter to retrieve json after script execution
s.converters["script json"] = function() {
if ( !responseContainer ) {
jQuery.error( callbackName + " was not called" );
}
return responseContainer[ 0 ];
}; // force json dataType
s.dataTypes[ 0 ] = "json"; // Install callback
overwritten = window[ callbackName ];
window[ callbackName ] = function() {
responseContainer = arguments;
}; // Clean-up function (fires after converters)
jqXHR.always(function() {
// Restore preexisting value
window[ callbackName ] = overwritten; // Save back as free
if ( s[ callbackName ] ) {
// make sure that re-using the options doesn't screw things around
s.jsonpCallback = originalSettings.jsonpCallback; // save the callback name for future use
oldCallbacks.push( callbackName );
} // Call if it was a function and we have a response
if ( responseContainer && jQuery.isFunction( overwritten ) ) {
overwritten( responseContainer[ 0 ] );
} responseContainer = overwritten = undefined;
}); // Delegate to script
return "script";
}
});
$('li.caption').live("hover",function () {
$(".cover", this).stop().animate({ top: '0px' }, { queue: false, duration: 160 });
}, function () {
$(".cover", this).stop().animate({ top: '-307px' }, { queue: false, duration: 160 });
或者你设置你的
$.ajax({
type: "get",
dataType: "html",
url: '/Ashx/act.ashx',
data: sql,
async:flase,//设置为同步请求,让这段ajax 执行完毕再在执行别的操作
success: function (data) {
$("#" + showul).html(data)
},
});