我无法成功地将jQuery链接到我的HTML。 我已经做了最简单的jQuery代码,所以我知道这是正确的,我已经尝试了所有我能想到的 – search没有帮助。 我的HTML(文件名:“test.html”: <!DOCTYPE html> <html> <head> <title>Test</title> <link rel="stylesheet" type="css/text" href="test.css"/> <script type="text/javascript" src="test.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script> </head> <body> <div id="orange"></div> </body> </html> 我的CSS(文件名:“test.css”): #orange { height: 100px; width: 100px; background-color: orange; border-radius: 5px; border: 3px solid black; margin-left: 100px; margin-top: 100px; display: none; } 我的JS(文件名:“test.js”): $(document).ready(function() { $('div').fadeIn('slow'); }); 控制台显示jQuery链接在6.52s加载。 […]
我有一个div.scroll_fixed与下面的CSS .scroll_fixed { position:absolute top:210px } .scroll_fixed.fixed { position:fixed; top:0; } 当div到达页面的顶部时,我使用下面的jQuery代码来设置.fixed类。 var top = $('.scroll_fixed').offset().top – parseFloat($('.scroll_fixed').css('margin-top').replace(/auto/, 0)); $(window).scroll(function (event) { // what the y position of the scroll is var y = $(this).scrollTop(); // whether that's below the form if (y >= top) { // if so, ad the fixed class $('.scroll_fixed').addClass('fixed'); } […]
不知道为什么这不起作用。 当用户点击我的应用程序的“编辑”button时,禁用的文本框就可以编辑了: $("#bewerken").click(function(e) { $("input[disabled='disabled']").removeAttr('disabled'); }); 然后我想在用户保存时再次禁用文本框; 我有这个代码绑定到我的保存button: $("#save_school_changes").click(function(e) { //stuff $.ajax({ type: "POST", url: "/school/save_changes", data: { //stuff }, success: function(data) { $("#feedback_top").html("<p>" + data['message'] + "</p>").slideDown('slow').delay(2000).slideUp(); $("input[type='text']").attr('disabled', 'disabled'); } }); e.preventDefault(); }); 据我所知,这应该再次禁用文本字段。 但是,这似乎并没有在Chrome中工作。 它在Firefox中工作。 我还没有机会在IE或Safari中testing。 有没有什么办法可以在Chrome浏览器中工作? 非常感谢!
坚持使用官方的jQuery API,是否有一种更简洁,但并不低效的方式来find与给定select器匹配的元素的下一个兄弟,而不是使用nextAll :first伪类? 当我说官方API时,我的意思是不要黑客内部,直接去Sizzle,在插件中添加一个插件等等。(如果我最终必须这样做,那就这么做吧,但这不是这个问题。 ) 例如,给定这种结构: <div>One</div> <div class='foo'>Two</div> <div>Three</div> <div class='foo'>Four</div> <div>Five</div> <div>Six</div> <div>Seven</div> <div class='foo'>Eight</div> 如果我有一个div (也许在一个click处理程序,无论),并希望find下一个匹配select器“div.foo”的兄弟div,我可以这样做: var nextFoo = $(this).nextAll("div.foo:first"); …这是行得通的(如果我以“Five”开头,比如跳过“Six”和“Seven”,为我find“Eight”),但是它很笨重,如果我想匹配任何几个select器,它变得很笨重。 (当然,这比原始的DOM循环会更简洁…) 我基本上想要: var nextFoo = $(this).nextMatching("div.foo"); nextMatching可以接受所有select器。 我总是感到惊讶, next(selector)不这样做,但它不,并且文档清楚它是干什么的,所以… 我可以随时编写它并添加它,但是如果我这样做,并坚持发布的API,事情变得相当低效。 例如,一个天真的next循环: jQuery.fn.nextMatching = function(selector) { var match; match = this.next(); while (match.length > 0 && !match.is(selector)) { match = match.next(); } […]
我想获得一个Ajax的代码后面的webmethod。 问题是我不断从jQuery的onfail方法得到错误“parserror”。 如果我将GET更改为POST,一切正常。 请参阅下面的代码。 Ajax调用 <script type="text/javascript"> var id = "li1234"; function AjaxGet() { $.ajax({ type: "GET", url: "webmethods.aspx/AjaxGet", data: "{ 'id' : '" + id + "'}", contentType: "application/json; charset=utf-8", dataType: "json", async: false, success: function(msg) { alert("success"); }, error: function(msg, text) { alert(text); } }); } </script> 代码在后面 [System.Web.Services.WebMethod] [System.Web.Script.Services.ScriptMethod(UseHttpGet = true, ResponseFormat […]
我从服务器得到下面的JSONstring作为响应 [{"city":"AMBALA","cStatus":"Y"},{"city":"ASANKHURD","cStatus":"Y"},{"city":"ASSANDH","cStatus":"Y"}] 这是我的JQuery代码 $('#search').click(function() { alert("submit handler has fired"); $.ajax({ type: 'POST', url: 'cityResults.htm', data: $('#cityDetails').serialize(), success: function(data){ alert(data); }, error: function(jqXHR, textStatus, errorThrown){ alert('error: ' + textStatus + ': ' + errorThrown); } }); return false;//suppress natural form submission }); 该警报正确显示JSONstring。 现在我想把这个响应映射到我的表 说 我怎样才能做到这一点 ??
我有一个html文件,我想打开并阅读,但我不完全知道如何做…基本上,这是一个相当大的文件(big.html),并在一个单独的文件( titles.html),我有一些jQuery代码,我想用它来查找某些元素(即h2标签),并从这些标签中获取内部文本,然后将这些文本写入titles.html …我是不知道,特别是如何打开一个单独的文件,并从中读取,其次,我不知道下面的代码是否会工作,当获得在h2标签内的文本… $(document).ready(function() { $("h2").each(function() { var title = $(this).text(); $("#mydiv").append(title); }); }); … <div id="mydiv"></div> 我有点困惑如何做到这一点与jquery …我是相当新的整个事情,所以我甚至不知道这是可能的…
我有一块表单元素,我想克隆和增加他们的ID使用jQuery的克隆方法。 我已经尝试了一些例子,但是其中很多只是克隆了一个字段。 我的块是这样构成的: <div id="clonedInput1" class="clonedInput"> <div> <div> <label for="txtCategory" class="">Learning category <span class="requiredField">*</span></label> <select class="" name="txtCategory[]" id="category1"> <option value="">Please select</option> </select> </div> <div> <label for="txtSubCategory" class="">Sub-category <span class="requiredField">*</span></label> <select class="" name="txtSubCategory[]" id="subcategory1"> <option value="">Please select category</option> </select> </div> <div> <label for="txtSubSubCategory">Sub-sub-category <span class="requiredField">*</span></label> <select name="txtSubSubCategory[]" id="subsubcategory1"> <option value="">Please select sub-category</option> </select> </div> </div> 很显然,元素排好了很多,但你明白了。 […]
我正在通过jQuery $ .ajax加载图像path,并显示图像之前,我想检查它是否存在。 我可以使用图像加载/就绪事件或类似的东西来确定文件path是有效的吗? .myimage设置为显示:无,我希望能做类似的事情 $(".myimage").attr("src", imagePath); $(".myimage").load(function() { $(this).show(); }); 有这样的可能吗?
如何通过JavaScriptdynamic地删除会话cookie,而无需手动重启浏览器? 我在某处读到会话cookie保存在浏览器内存中,当浏览器closures时会被删除。 // sessionFooCookie is session cookie // this code does not delete the cookie while the browser is still on jQuery.cookie('sessionFooCookie', null); 谢谢。 更多信息:上面的代码片段是一个JavaScript代码片段,使用jQuery和它的jQuery.cookie插件。