Tag: javascript

在Jasmine嘲笑xhr

我有一个关于在Jasmine中嘲笑xhr的问题。 我有以下Javascript情况: function Test1(){ // some code Test2({ readyState: 4, responseText: “”, status: 200, statusText: “OK” }); } function Test2(xhr){ var token = xhr.getResponseHeader(“csrftoken”); var csrfCtrl = $(“#token”); if (token != null && csrfCtrl != null) { csrfCtrl.val(token); } } 现在我想窥探xhr.getResponseHeader()函数,但我无法知道如何做到这一点。 我试过这样的事情: describe(“1 || Test ||”, function () { // Before we describe the tests […]

动态更改DOM元素,因为它们被滚动到视图中(性能)

我正在尝试找到一种有效的算法来为一堆 动态加载背景图像,并且存在一些效率问题。 我当前的代码如下所示: function elementInView($elem, vps, vpe) { var elempos = $elem.position(); var pagestart = elempos.top + vps; var pageend = elempos.top + vps + $elem.height(); var offset = 78 – Math.max(0,vps-pagestart) – Math.max(0,pageend-vpe); // I want to update all items that are within 200 pixels of // the current viewport return (vpe > 0 […]

从JavaScript传递并获取ID到PHP控制器

我有一个内联可编辑表(我使用了Tabledit ),每行都有一个ID,ID应传递给控制器​​操作(Yii2),以便我将编辑后的数据保存到数据库中。 这是我的js文件中的Tabledit代码: file.assetID = info.response; // the ID for (var i = 0; i < file.length; i++) { // the table if (file[i].type == "image/jpeg") { var type = "photo"; } else if (file[i].type == "video/mp4") { var type = "video"; } messageHtml += '’; messageHtml += ” + file[i].assetID + ”; messageHtml += […]

JQuery使用location.href的值

如何使用jQuery值与urh一起使用location.href? 每次以下url为例时,url都会有所不同。 URL作为数据库存储在数据库中 audit.php?审计= 13957911461655047299&页=汇总 然后使用Ajax检索URL并保存在名为last_viewed的var中,因此我想使用等效的 location.href = last_viewed 我试过了 location.href = ‘”‘+last_viewed+'”‘ 但URL变为 http://www.x-rayqa.co.uk/“audit.php?audit = 13957911461655047299&page = summary” 这显然不会因为额外的“s”而起作用 如果我试试 location.href = last_viewed 什么都没发生,脚本坏了。

如何在添加新表单时保持表单的焦点?

这是一个小提琴: FIDDLE function blanker(){ var c = $(‘.whatever’).html().replace(“thisWillBlank”, “”); $(‘.whatever’).html(c); } $(‘#alreadyBlanked’).focus(); setTimeout(function(){blanker()}, 3000); 使用JS / jquery / css我只想点击任何一种forms,即使出现新的forms也能保持焦点。 谢谢。

Featherlight隐藏div关闭

我正在尝试创建一个提交数据的预览屏幕,并将其显示在Featherlight Lightbox中。 我有以下示例代码。 jQuery(document).ready(function() { //Triggle when Preview Button is Clicked. jQuery(‘.OpenLightBox’).off(‘click’).on(‘click’, function( e ) { var pa_firstname= jQuery(‘input[name=”pa-[name_first]”]’).val(); var pa_lastname= jQuery(‘input[name=”pa-[name_last]”]’).val(); if (pa_firstname == null || pa_firstname == ”) { alert(‘Cannot be empty’); return false; } else { jQuery(‘.LightBox’).empty(); jQuery(‘.LightBox’).append(‘First Name in Ajax is’ + pa_firstname + ‘ And Last Name in Ajax is […]

jQuery Knob Release函数附加参数

我正在使用jQuery Knob插件https://github.com/aterrien/jQuery-Knob 现在,我有以下jQuery旋钮初始化 loop <input type="text" value="” class=”circle-rating” data-entryid=””> endloop $(function() { $(“.circle-rating”).knob({ ‘min’:0, ‘max’:10, ‘step’:1, ‘width’:40, ‘height’:40, ‘fgColor’:”#F59B00″, ‘inputColor’:”#F59B00″, ‘displayPrevious’: true, ‘release’ : function (v) { var entry_id = $(this).attr(‘data-entryid’); jQuery.post(“/path/to/file/update_library_score.php”, {v : v, entry_id : entry_id}, function(data) { console.log(entry_id); jQuery(‘#notification-general’).html(entry_id); }); } }); }); 主要问题是我在页面上有多个旋钮。 这些旋钮实际上是一个带有wordpresspost的循环。 无论如何,每个旋钮都附加到一个ID ,当你通过循环时,这个ID发生变化。 现在为了能够更新分数,我需要两个东西,即从release函数获得的旋钮value ,我还需要post_id ,我只能在循环内获得。 那么如何才能将post_id变量赋予此函数? 通常我只需添加一个button或带有onclick=”my_function()但是,我不能用这个来做。抓住与你对应的$ […]

Jquery / Javascript:通过按下按钮显示数组中的随机图像

var images = [“http://sofzh.miximages.com/javascript/200px-Playing_card_heart_5.svg.png”, “http://sofzh.miximages.com/javascript/short-link.jpg”, ]; function myFunction() { var x = Math.floor((Math.random() * images.length); $(‘#afbeelding’).attr(‘src’, images[x]); } HTML: Try it

如何使用jQuery或JavaScript基于当前URL和单击事件将一个类“active”分配给li元素

我正在尝试创建一个菜单,只要选择并加载了一个类“active”就会被分配给该页面。 现在它默认仅应用于索引页面。 我的菜单片段: Main News Contacts

从后面的代码调用javascript方法

我需要使用后面的代码中的参数调用JavaScript方法。 Javascript方法 function changeControlSample(path) { $find(”).set_UserControlPath(path); $find(”).refresh(); } Updating… 页面背后的代码 protected Consultation controlconsultation = new Consultation(); protected void Page_Load(object sender, EventArgs e) { PartialUpdatePanel7.UserControlPath = “Espace_Candidat/Consultation.ascx”; controlconsultation.imageinfo += controlconsultation_imageinfo; Session[“controlconsultation”] = controlconsultation; } void controlconsultation_imageinfo(object sender, CommandEventArgs e) { PartialUpdatePanel7.UserControlPath = “Espace_Candidat/InfoEdition.ascx”; Page.ClientScript.RegisterStartupScript(this.GetType(), “CallMyFunction”, “changeControlSample(‘Espace_Candidat/InfoEdition.ascx’)”, true); } 用户控件的代码 public event CommandEventHandler imageinfo ; protected void […]