Jquery CSS 和 JS 限制元素 [英] Jquery CSS and JS to limited elements

查看:27
本文介绍了Jquery CSS 和 JS 限制元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的 Jquery 移动 CSS 和 JS 仅应用于页面上的一些有限元素,而不应用于其他元素.知道我该怎么做.

我有一些 Salesforce 标准客户门户,其中包含一个包含 Jquery、移动和 CSS 的选项卡.

现在,当我在 Customer Portal 中打开选项卡时,它会覆盖 Salesforce 标准样式.

谢谢

解决方案

取决于您使用的 jQuery Mobile 版本.

  1. 解决方案 1:

    • 修改mobileinit 上的全局设置,将ignoreContentEnabled 设置为true.但是,这会对应用性能产生负面影响,因为它会减慢处理/初始化小部件/元素的速度.

      <script src="jQuery.js"></script><脚本>$(document).on("mobileinit", function () {$.mobile.ignoreContentEnabled = true;});<script src="jQuery-Mobile.js"></script><头>

    • data-enhance="false" 添加到您希望 jQM 保持不变的元素或 div.

      <!-- 元素-->

      <input type="text" data-enhance="false">

<小时>

  1. 解决方案 2:

    • 通过为 keepNative 设置 .selector 来修改 mobileinit 上的 page 小部件默认值..selector 可以是 #id.class.

      • jQuery Mobile <= 1.3.x

        <script src="jQuery.js"></script><脚本>$(document).on("mobileinit", function () {$.mobile.page.prototype.options.keepNative = $.mobile.page.prototype.options.keepNative + ", input, #foo, .native";});<script src="jQuery-Mobile.js"></script><头>

      • jQuery Mobile >= 1.4.x

        <script src="jQuery.js"></script><脚本>$(document).on("mobileinit", function () {$.mobile.keepNative = $.mobile.keepNative + ", input, #foo, .native";});<script src="jQuery-Mobile.js"></script><头>

      在创建页面时,input、带有 #foo ID 的元素和带有 native 类的元素将保持原样.

<小时><块引用>

演示

I want to apply my Jquery mobile CSS and JS to only some limited elements and to no other elements on the page. any idea how I can do that.

I have some Salesforce standard Customer Portal in which I am including a tab which is having Jquery ,mobile and CSS.

Now when I open the tab in Customer Portal , then it overrides Salesforce standard styling.

Thanks

解决方案

Depending on jQuery Mobile version you're using.

  1. Solution 1:

    • Modify Global Settings on mobileinit, by setting ignoreContentEnabled to true. However, this affects app performance negatively, as it slows down processing/initializing widgets/elements.

      <head>
        <script src="jQuery.js"></script>
        <script>
          $(document).on("mobileinit", function () {
            $.mobile.ignoreContentEnabled = true;
          });
        </script>
        <script src="jQuery-Mobile.js"></script>
      <head>
      

    • Add data-enhance="false" to elements or div you want to keep untouched by jQM.

      <div data-role="content" data-enhance="false">
        <!-- elements -->
      </div>
      
      <input type="text" data-enhance="false">
      


  1. Solution 2:

    • Modify page widget defaults on mobileinit, by setting a .selector for keepNative. The .selector could be a <tag>, an #id or a .class.

      • jQuery Mobile <= 1.3.x

        <head>
          <script src="jQuery.js"></script>
          <script>
            $(document).on("mobileinit", function () {
              $.mobile.page.prototype.options.keepNative = $.mobile.page.prototype.options.keepNative + ", input, #foo, .native";
            });
          </script>
          <script src="jQuery-Mobile.js"></script>
        <head>
        

      • jQuery Mobile >= 1.4.x

        <head>
          <script src="jQuery.js"></script>
          <script>
            $(document).on("mobileinit", function () {
              $.mobile.keepNative = $.mobile.keepNative + ", input, #foo, .native";
            });
          </script>
          <script src="jQuery-Mobile.js"></script>
        <head>
        

      When page is being created, input, element with #foo ID and elements with native class, will be kept as is.


Demo

这篇关于Jquery CSS 和 JS 限制元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆