.removeClass()可在jsFiddle上使用,但不能在浏览器中使用 [英] .removeClass() working on jsFiddle but not in the browser

查看:70
本文介绍了.removeClass()可在jsFiddle上使用,但不能在浏览器中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery mobile并尝试删除一些类而不是编写一堆CSS.当我在jsFiddle中测试它时,它可以正常工作,但是当我在浏览器中查看它时,它却无法正常工作.我已经将脚本放入data-role ="page"内,因此应该正确加载该脚本.我也尝试过.trigger("updatelayout");但这似乎没有用.任何帮助将不胜感激,因为这本来应该是2分钟的任务变成2个小时的头痛.

Im using jquery mobile and trying to remove some classes instead of writing up a bunch css. When I test it in jsFiddle it works fine but not when I view it in the browser. Ive put the script inside the data-role="page" so it should of loaded correctly. Ive also tried .trigger("updatelayout"); but that did not seem to work. Any help would be much appreciated since this should have been a 2 minute task turn into 2 hour headache.

jquery:

$("#panelforminput div").removeClass("ui-shadow-inset ui-corner-all ui-btn-shadow ui-body-c");
$("#newdoctorDiv ul").removeClass("ui-shadow");

jsFddle:

http://jsfiddle.net/adam123/9XXcj/6/

这是萤火虫的标记:

<span id="panelforminput" class="ui-li-aside">
  <div class="ui-input-text ui-shadow-inset ui-corner-all ui-btn-shadow ui-body-c ui-mini">
    <input id="adddocFirstName" class="ui-input-text ui-body-c" type="text" data-mini="true"
    placeholder="John" value="" name="adddocFirstName">
  </div>
</span>

推荐答案

您需要将脚本放入文档中.在代码中准备好以使元素可用于脚本,还要确保已成功包含jQuery,请阅读

You need to put the script in document.ready in your code to make the elements available to your script also make sure you included jQuery successfully, read how jQuery works.

在大多数情况下,只要DOM层次结构具有以下功能,就可以立即运行脚本 完全建成.保证传递给.ready()的处理程序 在DOM准备好后执行,所以通常这是最好的 附加所有其他事件处理程序并运行其他jQuery代码的地方, 参考.

In most cases, the script can be run as soon as the DOM hierarchy has been fully constructed. The handler passed to .ready() is guaranteed to be executed after the DOM is ready, so this is usually the best place to attach all other event handlers and run other jQuery code, Reference.

这篇关于.removeClass()可在jsFiddle上使用,但不能在浏览器中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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