jQuery CSS和JS限制元素 [英] Jquery CSS and JS to limited elements
问题描述
我想将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:
-
通过将
-
修改全局设置.但是,这会降低应用程序的性能,因为它会减慢处理/初始化小部件/元素的速度.
ignoreContentEnabled
设置为 true ,在mobileinit
上Modify Global Settings on
mobileinit
, by settingignoreContentEnabled
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">
-
解决方案2:
-
通过设置
-
修改页面小部件默认为
mobileinit
. .selector 可以是<tag>
,#id
或.class
.
keepNative
的 .selector ,Modify page widget defaults on
mobileinit
, by setting a .selector forkeepNative
. 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屋!