JS初学者在这里.
我需要一个脚本帮助将不同的内容放在div中,具体取决于页面正文标记是否具有"home"类.
我试图使用.hasClass和.html来实现这一目标.看起来它应该非常简单,但我无法弄明白.缺乏正确的语法知识?声明不正确?我不知道,希望有人能指出我正确的方向!
if ($("body").hasClass("home") == true) {
("#mobilemenu").html("<a href="#">HOME</a>");
}
else {
("#mobilemenu").html("<a href="#">NOT HOME</a>");
}
Run Code Online (Sandbox Code Playgroud)
JSFiddle(目前什么都不做)在这里:http: //jsfiddle.net/aqyN4/
链接到其他JSFiddles或具有类似功能的问题非常欢迎!
谢谢,
阿里
Python和BeautifulSoup的新手.我有一个Python程序打开一个名为"example.html"的文件,在其上运行一个BeautifulSoup操作,然后在其上运行Bleach操作,然后将结果保存为文件"example-packaged.html".到目前为止,它正在为"example.html"的所有内容工作.
我需要修改它,以便打开文件夹"/ posts /"中的每个文件,在其上运行程序,然后将其保存为"/posts-cleaned/X-cleaned.html",其中X是原始文件名.
这是我的代码,最小化:
from bs4 import BeautifulSoup
import bleach
import re
text = BeautifulSoup(open("posts/example.html"))
text.encode("utf-8")
tag_black_list = ['iframe', 'script']
tag_white_list = ['p','div']
attr_white_list = {'*': ['title']}
# Step one, with BeautifulSoup: Remove tags in tag_black_list, destroy contents.
[s.decompose() for s in text(tag_black_list)]
pretty = (text.prettify())
# Step two, with Bleach: Remove tags and attributes not in whitelists, leave tag contents.
cleaned = bleach.clean(pretty, strip="TRUE", attributes=attr_white_list, tags=tag_white_list)
fout = open("posts/example-cleaned.html", "w")
fout.write(cleaned.encode("utf-8"))
fout.close()
print "Done"
Run Code Online (Sandbox Code Playgroud)
很高兴收到现有解决方案的帮助和指示!
我已经按照将Dropzone 与正常表单结合起来的教程来允许 Dropzone 上传和表单提交。该表格是一个申请表格,它应该在添加和不添加文件的情况下都可以使用。目前,它仅在将一个或多个文件添加到 Dropzone 时才起作用。
即使上传队列为空,我是否可以启用允许 Dropzone 处理表单提交的选项?
这是我初始化表单的方式:
Dropzone.options.general = {
paramName: 'tx_ddapplicationform_applicationformgeneral[form][files]', // The name that will be used to transfer the file
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 100,
maxFiles: 100,
addRemoveLinks: true,
previewsContainer: '.dropzone-previews', // we specify on which div id we must show the files
clickable: false,
// The setting up of the dropzone
init: function() {
var myDropzone = this;
console.log(myDropzone)
console.log("Dropzone init");
console.log(this.element.querySelector("input[type=submit]"))
// First change the button to actually tell …
Run Code Online (Sandbox Code Playgroud) 我有一个配置值存储为3.months
,另一个值是从计算返回的7.days
。
我需要找到他们的区别。什么是规范他们,使我可以减去的最简单和Railsiest方式7.days
从3.months
?我可以使用.to_i并乘以一天中的秒数,从而将.months转换为天数,但是要像这样计算从几个月到几秒到几天的时间,感觉太漫长了:
x = (3.months.to_i/86400).days
=> 90 days
x - 7.days
=> 83 days
Run Code Online (Sandbox Code Playgroud)
有没有更好的办法?
我在页面中有很多div,如下所示:
<div class="formitem food-6 group-7">
//content of div
<input type="checkbox"> //child of div
</div>
<div class="formitem food-7 group-7">
//content of div
<input type="checkbox"> //child of div
</div>
Run Code Online (Sandbox Code Playgroud)
当选中复选框时,我想将其父级唯一类的值存储在变量中,例如"food-6"或"food-7".我可以得到父类的所有类,如下所示:
parent = $(this).closest(".formitem").attr("class");
Run Code Online (Sandbox Code Playgroud)
哪能给我formitem food-7 group-7
.
我怎样才能得到"以食物开头的那个"?
我正在使用AngularJS + SQLite数据库构建PhoneGap应用程序.我有一个经典的"异步工作如何"与数据库查询的角度问题,得到错误"无法调用方法然后未定义".我希望有人可以帮助我看到我的方式的错误.
这是我的查询功能.此处的每个alert()都返回有意义的数据,表明事务本身是成功的:
.factory('SQLService', ['$q', '$rootScope', 'phonegapReady',
function ($q, $rootScope, phonegapReady) {
function search(query) {
alert("Search running with " + query);
var promise = db.transaction(function(transaction) {
var str = "SELECT category, id, chapter, header, snippet(guidelines, '<b>', '</b>', '...', '-1', '-24' ) AS snip FROM guidelines WHERE content MATCH '" + query + "*';";
transaction.executeSql(str,[], function(transaction, result) {
var resultObj = {},
responses = [];
if (result != null && result.rows != null) {
for (var i = 0; i …
Run Code Online (Sandbox Code Playgroud) 我有一个Typo3安装,有3个现有的布局选项.这些都是在page.ts文件中声明的,如下所示:
#normal layout:
[globalVar=TSFE:page|layout=0]
page.10.template.file = fileadmin/template/classic-page.html
page.includeCSS.screen = fileadmin/template/css/style.css
page.includeCSS.screen.media = screen
[global]
Run Code Online (Sandbox Code Playgroud)
它们都在page.ts文件中的这个列表中,如下所示:
TCEFORM.pages {
layout.altLabels.0 = Normal
layout.altLabels.1 = Startpage
layout.altLabels.2 = Landing page
}
Run Code Online (Sandbox Code Playgroud)
所有这些布局选项都显示在CMS中"编辑页面(X)">"外观"页面的可能布局选项的下拉列表中.便利!
现在我有一个闪亮的新模板,我想作为一个选项添加.我可以通过将此代码添加到page.ts来将其应用于特定的页面ID(例如,页面编号#563):
[globalVar = TSFE:id=563]
page.10.template.file = fileadmin/template/shinynewtemplate.html
[GLOBAL]
Run Code Online (Sandbox Code Playgroud)
但我似乎无法将其添加为下拉菜单中的新布局选项.我试过这个:
#shiny new layout:
[globalVar=TSFE:page|layout=3]
page.10.template.file = fileadmin/template/shinynewtemplate.html
page.includeCSS.screen = fileadmin/template/css/style.css
page.includeCSS.screen.media = screen
[global]
TCEFORM.pages {
layout.altLabels.0 = Normal
layout.altLabels.1 = Startpage
layout.altLabels.2 = Landing page
layout.altLabels.3 = Shiny new page
}
Run Code Online (Sandbox Code Playgroud)
但没有香蕉.它没有显示在外观布局列表中,因此我无法将其应用于页面.
我错过了什么?是否还有其他地方需要声明此模板文件,以便它在下拉列表中显示为一个选项?
我的AngularJS应用程序没有显示TemplateURL的内容(测试应用程序在localhost上运行,而不是file://),我无法让它在Plunkr上运行.请帮我找一下我做错了什么.
我的元素是这样的:
<div case-test=""></div>
Run Code Online (Sandbox Code Playgroud)
使用此指令,文本"这里是DIR的案例测试"出现在它应该:
.directive('caseTest', function () {
return {
restrict: 'A',
template: 'HERE IS CASE TEST IN DIR',
link: function (scope, element, attrs) {
console.log("Case test running")
}
};
});
Run Code Online (Sandbox Code Playgroud)
但是当我将指令更改为this时,case.html的内容不会出现.console.log运行并且不会出现错误:
.directive('caseTest', function () {
return {
restrict: 'A',
templateURL: 'case.html',
link: function (scope, element, attrs) {
console.log("Case test running")
}
};
});
Run Code Online (Sandbox Code Playgroud)
case.html位于Web应用程序的根目录中,与应用程序的index.html位于同一文件夹中.
为了你的观赏乐趣,我把它放在了一个普拉克里,它也不起作用.正如您所看到的,如果查看控制台输出,则两个指令都会运行,但只有第一个指令会打印出其模板.
我在这做错了什么?
javascript ×3
jquery ×3
angularjs ×2
asynchronous ×1
class ×1
dropzone.js ×1
forms ×1
html ×1
html-parsing ×1
php ×1
python ×1
templates ×1
typo3 ×1
typoscript ×1