Jquery CSS和JS有限的元素

Kau*_*Ray 2 jquery salesforce jquery-mobile

我想将我的Jquery移动CSS和JS仅应用于一些有限的元素,而不是页面上的其他元素.任何想法我怎么能这样做.

我有一些Salesforce标准客户门户网站,其中包括一个包含Jquery,mobile和CSS的选项卡.

现在,当我打开客户门户中的选项卡时,它会覆盖Salesforce标准样式.

谢谢

Oma*_*mar 6

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

  1. 解决方案1:

    • 修改全局设置mobileinit,通过设置ignoreContentEnabled.但是,这会对应用程序性能产生负面影响,因为它会降低处理/初始化窗口小部件/元素的速度.

      <head>
        <script src="jQuery.js"></script>
        <script>
          $(document).on("mobileinit", function () {
            $.mobile.ignoreContentEnabled = true;
          });
        </script>
        <script src="jQuery-Mobile.js"></script>
      <head>
      
      Run Code Online (Sandbox Code Playgroud)
    • 添加data-enhance="false"到您想要保持不受jQM影响的元素或div.

      <div data-role="content" data-enhance="false">
        <!-- elements -->
      </div>
      
      <input type="text" data-enhance="false">
      
      Run Code Online (Sandbox Code Playgroud)

  1. 解决方案2:

    • 通过设置.selector来修改页面窗口小部件默认值.该.selector可能是,一个或一个.mobileinitkeepNative<tag>#id.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>
        
        Run Code Online (Sandbox Code Playgroud)
      • 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>
        
        Run Code Online (Sandbox Code Playgroud)

      在创建页面时input,具有#fooID的元素和具有native类的元素将保持原样.


演示