`
waiting
  • 浏览: 232787 次
  • 性别: Icon_minigender_1
  • 来自: cq
社区版块
存档分类
最新评论

JavaScript jQuery tips

阅读更多

JS常用信息:

 

  1. IE错误提示“缺少标识符、字符串或数字”,检查JS文件中对象字面量是否最后包含逗号。比如
    var obj = {id: 1, name: 'test',};
     紧接'test'后那个逗号就会导致IE出错。而FireFox正常。

  2. jQuery操作下拉菜单选定某个项目功能在IE中似乎无效。兼容办法:
    document.getElementById( id ).selectedIndex = $('#' + id + " option[value='" + someval + "']").attr('index');
    
     
  3. jQuery判断DOM是否存在:
    // 判断DOM元素是否存在
    if ($('#id')[0] ) {
        do_fun();  // exists
    }
    if ($('#id').length > 0) {
        do_fun();
    }
    
     
  4. 错误的框架访问:

    $(window.top.document).find('#topFrame p').text();	
    $(window.parent.document).find('#topFrame').remove();
     

    正确的框架访问:

    $(window.parent.frames['left'].document).empty(); //删除左框架“内容”
     

    在顶级窗口中 改变框架本身属性,此时的框架是顶级窗口的一个DOM 对象

    $(window.parent.parent.document).find('#fs2').attr('cols', '155,*');
    $(window.top.document).find('#left').remove(); 
     

    以下是跨框架访问操作DOM 元素 . frames  + id 的方式最兼容

    window.top.document.getElementById('left').id;
    window.top.frames[0].document.getElementById('SendFlag').id;
    window.top.frames['topFrame'].document.getElementById('SendFlag').id;
    window.top.frames['left'].document.getElementById('mli0').name;
    $(window.top.frames['left'].document).find('#mli0').attr('id');
    $(window.top.frames['topFrame'].document).find('p').text('cqple');
    $('p', window.top.frames['topFrame'].document).text('cqple');
     

     

  5. 子窗口操作父窗口

    // jquery
    $("#父窗口元素ID",window.parent.document)...就行了
    //js 版本
    window.parent.document.getElementById()
     

  6. jQuery 对象

    var el = $(selector);  // 取到的el变量为jquery对象,el[0]则为 selector对象
    var node = el.jquery ? el[0] : el; // el.jquery 返回真(其实是jquery版本号)说明el为jquery对象
     
  7. jQuery ajax对提交值编码规则
    如果是字符串类型不编码,如果是对象则默认调用encodeURIComponent。所以如果$ajax data参数值是自己拼接的字符串那么就需要手工编码一次
    var pdata  = '&a=33' + '&b=' + encodeURIComponent('zz=3');
    // var pdata  = {a: 33, b: 'zz=3', c: 'z3&?aj=3', d: encodeURIComponent('z3&?aj=3')};
    
    $.ajax({
       type : "POST",
       url    : "some.php",
       data:  pdata
       success: function(msg){
         // do something
       }
    });
     






 

 

 

 

 

 

 

 

 

 

0
0
分享到:
评论

相关推荐

    jQuery提示tips特效代码.zip

    jQuery提示tips特效代码.zip

    Tips基于jQuery的提示框插件可自动消失可手动消失

    Tips 基于jQuery的提示框插件,可自动消失可手动消失

    js特效脚本含源码和说明jquery随机头像TIPS

    js特效脚本含源码和说明jquery随机头像TIPS本资源系百度网盘分享地址

    26个JQuery使用技巧

    This means that more and more useful jQuery tips, tricks and solutions are coming available. That’s why i created a small list of 26 cool and useful jQuery tips, tricks and solutions.

    Jquery下的26个实用小技巧(jQuery tips, tricks solutions)

    比如有禁止右键点击、隐藏搜索文本框文字、在新窗口中打开链接、检测浏览器、预加载图片、页面样式切换、所有列等高、动态控制页面字体大小、...类库、禁用Jquery效果、解决Jquery类库与其他Javascript类库冲突问题...

    Supercharged.JavaScript.Graphics(第1版)

    tips • Taking advantage of the surprising graphics power of regular DOM manipulation (DHTML) • Using the Canvas element for additional graphics power • Creating video games • Using math for ...

    Tips:一个精简的 jQuery 提示插件

    首先加载jQuery,并启用Tips插件: $ ( function ( ) { $ ( '.demo1' ) . tips ( { msg : 'This is a demo text.' } ) ; $ ( '.demo2, .demo3' ) . tips ( { skin : 'white' , msg : '' } ) ; } ) ;

    JQuery&CSS;&CSS;+DIV实例大全.rar

    6.jQuery带Tips动画提示通用表单验证插件下载(jquery validate),动画效果漂亮 7.jQuery鼠标移到下载地址滑出气泡提示效果的插件 8.又一款jquery实现链接Tip演示下载 9.常用jQuery弹出式链接提示效果Tooltip...

    jQuery Mobile

    Mobile applications come in two basic flavors: native applications, which are ... As jQuery Mobile advances, we hope to update this ebook to cover new features and provide new tips and techniques.

    showTips:Jquery插件Tips气泡提示插件

    showTips Jquery插件Tips气泡提示插件

    The JavaScript Pocket Guide

    Almost every website today uses some form of JavaScript, whether it be used within a server-side programming technology like ASP.NET or a JavaScript library like jQuery or Mootools, or YUI or ...

    移动端基于jqueryzepto的UI组件库

    移动端基于jquery,zepto的UI组件库,目前实现 JS Components:Toast、Action、Tips、Dialog、Swiper、CityPicker、DatetimePicker、Tab、Range Css Component:oneborder、Loading、button 等

    jquerynotify是一款简单实用的jQuery消息提示插件

    jquery-notify是一款简单实用的jQuery消息提示插件,该消息提示插件的特点是可以在显示提示框的时候发出声音。它简单实用,用户体验非常好

    JavaScript中利用jQuery绑定事件的几种方式小结

    //引入JQuery [removed][removed] <span id=tips> <input type=button id=btn1 value=OK1 onclick=alert('hello btn1');> <input type=button id=btn2 value=OK2 click-type=listener> <...

    jQuery插件:jQuery插件

    jQuery插件 jquery.pagination.js分页 jquery.dialog.js实施 jquery.tips.js提示框

    jQuery最佳实践

    本文主要参考了Addy Osmani的PPT《提高jQuery性能的诀窍》(jQuery Proven Performance Tips And Tricks)。他是jQuery开发团队的成员,具有一定的权威性,提出的结论都有测试数据支持,非常有价值。

    简单的jQuery入门指引

    jQuery可以说是web开发领域应用最为广泛的轻量级javascript库,不仅专业的web开发者使用它,很多刚入门的web开发者或者web爱好者也通过使用jQuery轻松地融入到了javascript的开发。 而如果你还希望在这方面做得更好...

    图库新版jQuery焦点图 JS代码

    document.write('<script type="text/javascript" >BAIDU_CLB_SLOT_ID = "288992";</script>'); document.write(ojs);} if (code=="top210x90_2"){ document.write('<script type="text/javascript" >BAIDU_CLB_SLOT...

    jQuery 弹窗对话框拖动 非插件

    <script language="javascript" src="js/jquery-1.4.min.js"> 网站管理员请求和您通话-<a href="http://www.vihchina.net" target="_blank">VIHCHINA.NET</a></h1><span id="doclose"></span> ...

    jQuery实现鼠标移到元素上动态提示消息框效果

    当光标移动到某些元素上时,会弹出像tips的提示框。 代码如下: <!DOCTYPE html> <html> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ /> <title>...

Global site tag (gtag.js) - Google Analytics