Tag: jQuery的

尝试从jQuery ajax获取响应中选择脚本标记

我在页面A上。单击了一个链接,我通过jQuery get从页面B加载到DOM中。内部页面B的DOM是多个动态生成的脚本标记,其中包含“dataScript”类以及一堆其他脚本标签,我不想要与之相关。 我想从DOM那里得到的唯一东西就是.dataScript标签,然后我想把它插入ID为“scriptOutput”的div到页面A的DOM中。如果元素的类为“ dataScript“是一个脚本标记。 只有它是其他标签,例如“div”标签。 这是我正在尝试做的一个例子: 页面A: Page A jQuery(function() { $(“#ajaxJsLink”).click(function() { $.get(“https://stackoverflow.com/questions/4430707/trying-to-select-script-tags-from-a-jquery-ajax-get-response/pageB.html”, function(data) { var scriptElements = $(data).find(“.dataScript”).contents(); console.log(scriptElements); $(scriptElements).each(function(index) { $(“#scriptOutput”).append($(this).html()); }); }); return false; }); $(“#ajaxDivsLink”).click(function() { $.get(“https://stackoverflow.com/questions/4430707/trying-to-select-script-tags-from-a-jquery-ajax-get-response/pageB.html”, function(data) { var scriptElements = $(data).find(“.dataDiv”).contents(); console.log(scriptElements); $(scriptElements).each(function(index) { $(“#divOutput”).append($(this).html()); }); }); return false; }); }); This is page A. Get JavaScript from […]

jquery – JSON到

我有Json的forms [{“id”:39,”data”:1},{“id”:40,”data”:2}] 它没有用jQuery.parseJSON()正确解析 我需要获取这些数据并创建一个html table 。 我正在考虑在js中动态创建HTML。 A.我如何解析json? B.动态HTML是最好的路线吗? 更新 我道歉。 显然我的问题不明确。 这是jquery $.get(‘Service.aspx’, { p1: value, p2: value }, function (data) { notesJson = data; alert(notesJson);//Json comes back as I said here… var noteSet = jQuery.parseJSON(notesJson); alert(noteSet.notes); }); Json中确实存在注释。 第二个警报失败“未定义”。

使用jQuery编辑表单时确认离开页面

我正在编写一个表单,我需要像stackoverflow这样的函数:“你已经开始编写或编辑post了。” 我已经查看了stackoverflow的代码,看看他们是如何做到这一点的,但是我根本没有把它应用到我的简单表单中。 这就是他们对question.js的看法: function initNavPrevention(b) { if (b.which == “undefined”) { return } var a = $(“#wmd-input”); a.unbind(“keypress”, initNavPrevention); setConfirmUnload(“You have started writing or editing a post.”, a) } 其中一个函数触发了这个(我不知道c是什么): if (c) { e.keypress(initNavPrevention) } 最后他们有setConfirmUnload(null); 我猜想禁用它。 我的情况很简单。 我有一个页面,我通过AJAX加载 ,我想阻止加载此表单离开页面而不点击SUBMIT按钮,或者如果用户单击CANCEL,表单被禁用,防止不会弹出。 拥有此代码,有人可以告诉我如何将其包含在我的网站上吗? 这是我加载表单的AJAX函数: $(“#projects_historics_edit_part_1”).click(function(){ $(“#ajax-loader”).fadeIn(‘normal’); $.ajax({ url: BASE_URL + ‘projects/ajax/get_historics_edit_part_1/’ + PROJECT_ID, type: “POST”, success: function(data) […]

如何使用Google Maps API v3.0强制重绘?

我有一个相当复杂的地图应用程序,可以处理多个自定义标记等。 我有一个名为resizeWindow的函数,我在监听器中调用它,每当屏幕更改时,映射会通过计算新边界并强制resize来重绘自身。 它看起来像这样: window.onresize = function(event) { fitmap(); }; 并且resize的function是: function fitmap(id) { var coords = []; var newlatlng = new google.maps.LatLng(projlat, projlng); coords.push(newlatlng); for (var i=0; i<markers[id].length; i++) { newlatlng = new google.maps.LatLng(markers[id][i].latitude, markers[id][i].longitude); coords.push(newlatlng); } } var bounds = new google.maps.LatLngBounds (); for (var i = 0, LtLgLen = coords.length; i < LtLgLen; […]

如何将jQuery添加到HTML页面?

我得到了这段代码放在我的html页面中,但我对javascript一无所知,所以我不知道在哪里放置它以及放置它的标签类型。 $(‘input[type=radio]’).change(function() { $(‘input[type=radio]’).each(function(index) { $(this).closest(‘tr’).removeClass(‘selected’); }); $(this).closest(‘tr’).addClass(‘selected’); });

jQuery:我得到OPTIONS请求而不是GET

我使用的是简单的jQuery $.get( …. ); 这里没有获得GET响应而是获得OPTIONS。(在firebug Net中检查) 相同的代码在Safari中正常工作。 看起来像Firefox的一些问题。 解决此问题的任何解决方法/解决方案.. 谢谢 Kurund

jquery 1.9.0直播function?

jquery 1.9.0中没有live()函数,但jquery.unobtrusive.ajax.js已经使用了这个函数。 我应该使用旧版本的jquery还是其他方式?

回调.delay()

我有一个$image .fadeIn和.fadeOut $image ,然后.fadeOut完成后.fadeOut .remove 。 这是我的代码: $image .fadeIn() .fadeOut(function() { $(this).remove(); }); 我想在.delay之后添加一个.delay ,并且只.delay一次$image .delay已完成。 我试过了: $image .fadeIn() .fadeOut() .delay(1000, function() { $(this).remove(); }); 问题是.delay 不接受回调函数。 我怎样才能将图片作为对.delay的回调.delay ?

jquery .live on load事件

我需要一种方法来使用jquery .live()函数来处理通过ajax加载的元素。 例如,通过ajax .load()加载div 通常我会使用click事件执行.live() ,但我需要知道如何告诉dom这个新的div已加载而没有来自用户的任何显式操作/事件。 这段代码不起作用,但我想做这样的事情: mydiv = $(“#mydiv”); mydiv.live(“mydiv.length > 0”, function() { // do something }); “mydiv.length”是典型“点击”或其他事件的替代品。

jquery,隐藏内容直到加载

我目前正在使用此脚本淡化页面转换: $(document).ready(function() { $(window).bind(“unload”, function() {}); $(“body”).css(“display”, “none”); $(“body”).hide(); $(“body”).fadeIn(2000); $(‘a.fade1, a.fade2, a.fade3, a.fade4’).click(function(event) { event.preventDefault(); linkLocation = this.href; $(“body”).fadeOut(700, redirectPage); }); function redirectPage() { window.location = linkLocation; } });​ 当内容在缓存中变为alred时,这就像一个魅力,但是当一个图像需要加载时,它会暂时出现然后被隐藏和淡入 所以我需要的是一种方法来隐藏内容,直到它完全加载,只有在它之后让它消失 希望有人可以帮助我,提前谢谢