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

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

问题描述

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

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.

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

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

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

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

谢谢

推荐答案

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

Depending on jQuery Mobile version you're using.

  1. 解决方案1:

    通过将ignoreContentEnabled设置为 true ,在mobileinit
  • 修改全局设置.但是,这会降低应用程序的性能,因为它会减慢处理/初始化小部件/元素的速度.

  • 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>

  • 向要由jQM保持不变的元素或div添加data-enhance="false".

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


    1. 解决方案2:

      通过设置keepNative .selector
    • 修改页面小部件默认为mobileinit. .selector 可以是<tag>#id.class.

    • 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

    • 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

  • 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>
    

  • 在创建页面时,input(具有#foo ID的元素和具有native类的元素)将保持不变.

    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天全站免登陆