Home Web Front-end JS Tutorial jquery question and answer knowledge compilation_jquery

jquery question and answer knowledge compilation_jquery

May 16, 2016 pm 06:34 PM
jquery Q&A

Get ID: $(this).attr("id");
:not usage
1. List usage

Copy code The code is as follows:

var notList = [];
notList.push("#<%=txtSuggest.ClientID %>");
var textElements = $("input[type=text]:not(" notList ")");
var firstFocusItem = null;
//Traverse the elements of Type=Text
textElements.each(function(i) {
//TODO
});

2. Exclusive usage
Copy code The code is as follows:

$("table[id^=tb]:not([id=tbBasicInfo])").each(function() {
alert($(this ).attr("id"));
});

If [] is not added, $("table[id^=tb]:not(tbBasicInfo)"), This is not possible
At this time, not is based on the former tb with id^=tb: not operation
Restore BackGround-Color to the original color
background-color:transparent
Remove the underline of Href , visited styles
a, a:visited{ text-decoration: none;}
Remove Li’s point style
li{margin:0; padding:0; list-sytle:none}
Get a certain style in the Style of the current object
$("#divDept").css("display")
CSS BackGround Url cannot be displayed
Because IE browser and FF have different processing paths There are some differences. Modify the boxy.css code under IE as follows.
Copy code The code is as follows:

.boxy-wrapper .top-left { background: url ('images/boxy-nw.png'); }
.boxy-wrapper .top-right { background: url('images/boxy-ne.png'); }
.boxy-wrapper .bottom -right { background: url('images/boxy-se.png'); }
.boxy-wrapper .bottom-left { background: url('images/boxy-sw.png'); }
/* IE6 7 hacks for the border. IE7 should support this natively but fails in conjuction with modal blackout bg. */
/* NB: these must be absolute paths or URLs to your images */
.boxy- wrapper .top-left { #background: none; #filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/boxy-nw.png'); }
.boxy-wrapper .top-right { #background : none; #filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/boxy-ne.png'); }
.boxy-wrapper .bottom-right { #background: none; #filter:progid: DXImageTransform.Microsoft.AlphaImageLoader(src='images/boxy-se.png'); }
.boxy-wrapper .bottom-left { #background: none; #filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src= 'images/boxy-sw.png'); }

This will display normally under IE.
Get Table object
$("table[id=tableID]") or $("#tableID")CountDown usage
Copy code The code is as follows:

$.getJSON(

loginServiceUrl,{ method: "Logout"},

function(result) {

if (result.Url != null) {

$("#transfer").countdown({
until: " 5s",
expiryUrl: result.Url,
onTick: function(periods){
$(this).text(periods[6]);
}
});
}
});

There is a problem with text() value in Google Chrome, change it to val()
Problem with window maximization in Google Chrome
The following js code works fine in FF and IE
Copy code The code is as follows:

if (window.screen) {
var myw = screen.availWidth;
var myh = screen.availHeight;
window.resizeTo(400, 400);
window.moveTo(0, 0);
}

  • 在Chrome中resizeTo,resize都是没有效果的。

Issue 2091:window.resizeTo() doesn't have any effect

  • By Design we don't support resize/move for tabs, only constrained windows.

http://www.cnblogs.com/lonz/articles/381022.html

  • javascript resizeTo bug

http://code.google.com/p/chromium/issues/detail?id=11523

  • 在google chrome/safari 中textbox默认是可以自由拉长的,为何控制不让其自由拉长。

clip_image001

解决方案:

CSS to disable resizing

textarea {
resize: none;
}
<textarea <SPAN style="COLOR: #0000ff">name</SPAN>="<SPAN style="COLOR: #8b0000">foo</SPAN>">

textarea[<span style="COLOR: #0000ff">name</span>=foo] {
resize: none;
}

HTML is <textarea id="<SPAN style="COLOR: #8b0000">foo</SPAN>">)

#foo {
resize: none;
}
Copy after login

 

  • JS压缩工具

http://www.brainjar.com/js/crunch/demo.html

缺点:

会把正则表达式中类似*/去除

Sample:

value = s.replace(/^0*/, '');

After Compress:

value = s.replace(/^0, '');

  • parseInt() 和 Number() 兩個函數有什么不同?

http://hi.baidu.com/iloverobot/blog/item/bd3ed651ffd362868c5430bf.html

  • JSON 问题

http://blog.csdn.net/chinaontology/archive/2007/12/30/2004871.aspx

  • CSS置底的提示框

clip_image002

clip_image003

  • 大文件上传 进度条显示 (仿csdn资源上传效果)

http://www.cnblogs.com/zengxiangzhan/archive/2010/01/14/1647866.html

  • 可编辑的Input

http://acme.com/javascript/

clip_image004

  • jquery设置html头信息

http://home.phpchina.com/space.php?uid=155537&do=blog&id=182698

  • jQuery与prototype(ajaxpro)冲突的解决方法

http://www.cnblogs.com/sxlfybb/archive/2009/06/04/1495995.html

  • 利用jQuery + Handler(ashx) + LINQ 實現 Autocomplete

http://www.dotblogs.com.tw/puma/archive/2009/03/10/7426.aspx

  • jquery ajax 中文乱码

http://phpxiaoxin.javaeye.com/blog/350544

  • Ajax中文乱码原因分析及解决方案

http://hi.baidu.com/sihillver/blog/item/4d6f32f592920325bc3109d7.html

  • 打造基于jQuery的高性能TreeView

http://kb.cnblogs.com/page/50337/

http://kb.cnblogs.com/page/53517/

  • 利用jQuery实现更简单的Ajax跨域请求

http://kb.cnblogs.com/page/53433/

  • Jquery.Ajax 读取XML
<span style="COLOR: #800000">first</span> <span style="COLOR: #800000">of</span> <span style="COLOR: #800000">all</span> <span style="COLOR: #800000">sorry</span> <span style="COLOR: #800000">about</span> <span style="COLOR: #800000">my</span> <span style="COLOR: #800000">english</span>, <span style="COLOR: #800000">it</span>'<span style="COLOR: #800000">s</span> <span style="COLOR: #800000">not</span> <span style="COLOR: #800000">my</span> <span style="COLOR: #800000">native</span> <span style="COLOR: #800000">lengauge</span>...
<span style="COLOR: #800000">i</span> <span style="COLOR: #800000">have</span> <span style="COLOR: #800000">a</span> <span style="COLOR: #800000">xml</span> <span style="COLOR: #800000">file</span> <span style="COLOR: #800000">that</span> <span style="COLOR: #800000">i</span>'<span style="COLOR: #800000">m</span> <span style="COLOR: #800000">reading</span> <span style="COLOR: #800000">with</span> <span style="COLOR: #800000">the</span> <span style="COLOR: #800000">sample</span> <span style="COLOR: #800000">code</span> <span style="COLOR: #800000">above</span>... 
Copy after login
<span style="COLOR: #800000">but</span> <span style="COLOR: #800000">when</span> <span style="COLOR: #800000">i</span> <span style="COLOR: #800000">try</span> <span style="COLOR: #800000">to</span> <span style="COLOR: #800000">read</span> <span style="COLOR: #800000">it</span> <span style="COLOR: #800000">from</span> <span style="COLOR: #800000">a</span> <span style="COLOR: #800000">service</span> <span style="COLOR: #800000">web</span> <span style="COLOR: #800000">page</span> (<span style="COLOR: #800000"><a href="http://www.google.com/ig/api?weather=Buenos%20A">http</a></span>://<span style="COLOR: #800000">www</span>.<span style="COLOR: #800000">google</span>.<span style="COLOR: #800000">com</span>/<span style="COLOR: #800000">ig</span>/<span style="COLOR: #800000">api</span>?<span style="COLOR: #800000">weather</span>=<span style="COLOR: #800000">Buenos</span>%<span style="COLOR: #800000">20A</span>...), 
Copy after login
<span style="COLOR: #800000">it</span> <span style="COLOR: #800000">doesn</span>'<span style="COLOR: #800000">t</span> <span style="COLOR: #800000">show</span> <span style="COLOR: #800000">anything</span>... <span style="COLOR: #800000">and</span> <span style="COLOR: #800000">if</span> <span style="COLOR: #800000">i</span> <span style="COLOR: #800000">write</span> <span style="COLOR: #800000">the</span> <span style="COLOR: #800000">same</span> <span style="COLOR: #800000">content</span> <span style="COLOR: #800000">of</span> <span style="COLOR: #800000">this</span> <span style="COLOR: #800000">page</span> <span style="COLOR: #800000">in</span> <span style="COLOR: #800000">a</span> <span style="COLOR: #800000">xml</span> <span style="COLOR: #800000">file</span> <span style="COLOR: #800000">in</span> <span style="COLOR: #800000">my</span> <span style="COLOR: #800000">pc</span>, 
Copy after login
<span style="COLOR: #800000">it</span> <span style="COLOR: #800000">works</span> <span style="COLOR: #800000">perfectly</span>... <span style="COLOR: #800000">i</span> <span style="COLOR: #800000">dont</span> <span style="COLOR: #800000">know</span> <span style="COLOR: #800000">what</span> <span style="COLOR: #800000">am</span> <span style="COLOR: #800000">i</span> <span style="COLOR: #800000">doing</span> <span style="COLOR: #800000">wrong</span>
<span style="COLOR: #800000">i</span> <span style="COLOR: #800000">let</span> <span style="COLOR: #800000">u</span> <span style="COLOR: #800000">the</span> <span style="COLOR: #800000">code</span> <span style="COLOR: #800000">that</span> <span style="COLOR: #800000">i</span>'<span style="COLOR: #800000">m</span> <span style="COLOR: #800000">using</span> <span style="COLOR: #800000">maybe</span> <span style="COLOR: #800000">u</span> <span style="COLOR: #800000">could</span> <span style="COLOR: #800000">help</span> <span style="COLOR: #800000">me</span>
<span style="COLOR: #800000">function</span> <span style="COLOR: #800000">clima</span>(){
$.<span style="COLOR: #ff0000">ajax</span>(<span style="COLOR: #0000ff">{
  type: "GET",
  url: 'http://www.google.com/ig/api?weather=Buenos%20Aires',
  dataType: "xml",
  success: function(data){
  var $weather = $(data).find('current_conditions')
   console.log($weather)</span>;
  }
 });
}

<span style="COLOR: #800000">function</span> <span style="COLOR: #800000">clima</span>() {
$.<span style="COLOR: #ff0000">ajax</span>(<span style="COLOR: #0000ff">{
  type: "GET",
  dataType: "xml",
  url: 'http://www.google.com/ig/api?weather=Buenos%20Aires',
  success: function(xml) {
  var weather = $(xml).find("current_conditions").find("temp_c").attr("data")</span>;
<span style="COLOR: #ff0000">   alert</span>(<span style="COLOR: #0000ff">"Prognostico para hoy: " + weather + " grados")</span>;
  }
 });
}
Copy after login

 

  • FullSize:一个新的IMG标签属性(附带JQuery实现)

http://css9.net/img-fullsize/

clip_image005

http://css9.net/wp-content/uploads/2009/04/fullsize/example.html

有关于$.ajaxSetup和$.get的问题

在Common.js中使用

  $.ajaxSetup({
    url: "<span style="COLOR: #8b0000">…..</span>",
    type: "<span style="COLOR: #8b0000">POST</span>",
    cache: <span style="COLOR: #0000ff">true</span>,
    dataType: "<span style="COLOR: #8b0000">json</span>"
  });
  $.ajax({
    data: { cityCode: cityCode, flag: flag },
    success: <span style="COLOR: #0000ff">function</span>(areaList) { …}

  });
Copy after login

在PageA页面引入Common.js

   然后在脚本段中使用 $.get(url);

  此处url调用的是一个aspx页面,显示结果为无数据加载!(正常情况:有数据加载。)

  然后经过使用IE8的开发人员工具,进行Trace Error.最终发现原因错误信息(如下)

  "Invalid JSON:

"form1" method="post" action="ajax_select

那么如何解决呢?

原因:

        肯定是请求数据类型有问题?

解决方案:

        1.在Page A 页面脚本段 $.get(url,“html”); 

          因为$.get中的Data是可选项,现在确定原因之后,我们就来预定义好DataType

       结果:OK

分析源由:

     是因为$.ajaxSetup是用全局设定的,所以全局已经设定了DataType:JSON了。

     那Page A 页面的$.get()肯定受及影响。

image

最终解决方案:

    改Common.js,去掉ajaxSetup全局设定

       $.ajax({ url: "…..", type: "POST", cache: true, dataType: "json",data: { cityCode: cityCode, flag: flag }, success: function(areaList) { …} });

    结果:OK

     image

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of jQuery reference methods: Quick start guide Detailed explanation of jQuery reference methods: Quick start guide Feb 27, 2024 pm 06:45 PM

Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

How to remove the height attribute of an element with jQuery? How to remove the height attribute of an element with jQuery? Feb 28, 2024 am 08:39 AM

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

How to use PUT request method in jQuery? How to use PUT request method in jQuery? Feb 28, 2024 pm 03:12 PM

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: &lt

Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on ​​the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

How to tell if a jQuery element has a specific attribute? How to tell if a jQuery element has a specific attribute? Feb 29, 2024 am 09:03 AM

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

Understand the role and application scenarios of eq in jQuery Understand the role and application scenarios of eq in jQuery Feb 28, 2024 pm 01:15 PM

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s

Summary of commonly used file operation functions in PHP Summary of commonly used file operation functions in PHP Apr 03, 2024 pm 02:52 PM

目录1:basename()2:copy()3:dirname()4:disk_free_space()5:disk_total_space()6:file_exists()7:file_get_contents()8:file_put_contents()9:filesize()10:filetype()11:glob()12:is_dir()13:is_writable()14:mkdir()15:move_uploaded_file()16:parse_ini_file()17:

See all articles