我想要完成的是当用户专注于文本框时,其中的字段集将添加一个类"active_fieldset",因此它提供了一个很好的视觉提示,表明用户在表单中的位置.使用以下javascript,它确实会影响父字段集,但它也会影响所有兄弟字段集.难道我做错了什么?我的HTML或javascript是否存在根本性问题?
示例HTML:
<div id="content">
<form action="next_page" method="post">
<fieldset>
<legend>Foo</legend>
<p><label for="one">One</label> <input type="text" class="input_text" name="one" value="" id="one"></p>
</fieldset>
<fieldset>
<legend>Bar</legend>
<p><label for="two">Two:</label><input type="text" class="input_text" name="two" value="" id="two"></p>
</fieldset>
<p><input type="submit" value="Continue →"></p>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
form.js:
$(document).ready(function(){
$('.input_text').focus(function(){
$(this).parents('fieldset').addClass("active_fieldset");
});
});
Run Code Online (Sandbox Code Playgroud)
编辑:
我已经包含了我的CSS:
fieldset
{
border-width: 10px 0 0 0;
border-style: solid;
border-color: #0D6EB8;
}
fieldset.active_fieldset
{
border-width: 10px 0 0 0;
border-style: solid;
border-color: #0D6EB8;
}
Run Code Online (Sandbox Code Playgroud) 有谁知道我在哪里可以找到一个SQL转储形式的英语单词列表?
我在网上找到了一个单词列表,但它是一个大的纯文本文件; 单词由新行字符分隔.我尝试编写一个PHP脚本来循环显示单词并将它们插入到数据库中,但很快就会在读取大文件时遇到内存问题.我已将文件拆分为4个较小的文件,但我仍然遇到内存错误.如果有人知道如何将我当前的文件转换为更加导入的朋友格式,请告诉我.
我遇到了Python的错误.请参阅下面的代码示例.我运行event_timer.py,我收到以下错误消息.下面列出的两个文件都在同一个文件夹中.
Traceback (most recent call last):
File "E:\python\event_timer\event_timer.py", line 7, in
timer = EventTimer()
TypeError: 'module' object is not callable
我错过了什么?
event_timer.py:
import EventTimer
timer = EventTimer()
timer.addStep("Preheat Oven", seconds = 10)
timer.addStep("Cook Pizza", seconds = 20)
timer.addStep("Done!")
timer.start()
Run Code Online (Sandbox Code Playgroud)
EventTimer.py:
import time
class Timer:
event = 'Event'
steps = []
def __init__(self, event = None):
if event is not None:
self.event = event
def addStep(self, step, seconds = None, minutes = None, hours = None, days = None): …Run Code Online (Sandbox Code Playgroud) 如果你看一下下面的函数,就在它的第11行alert(template);.它打印undefined.如果我alert(template);在ajax成功回调中,它打印没有问题.由于模板是在函数顶部定义的,因此整个函数不应该是全局的吗?有人可以帮助我吗?
function load_template(path, data, callback){
var template;
$.ajax({
url: path,
success: function(uncompiled_template){
template = Handlebars.compile(uncompiled_template);
}
});
alert(template);
if(callback){
callback(template, data);
}else{
return template(data);
}
}
Run Code Online (Sandbox Code Playgroud) 使用AngularJS遇到令人沮丧的问题.我要做的就是加载一个json文件并使用ng:repeat在模板中显示它.我过去没有遇到任何问题,但出于某种原因,下面的代码不起作用.有人可以看看,告诉我我错过了什么?
如果你看模板:
palette.html
{{palette}}
<div ng-repeat="for color in palette">{{color}}</div>
Run Code Online (Sandbox Code Playgroud)
{{palette}}[{"hex":"#6e4516"},{"hex":"#DDDABE"},{"hex":"#ECEAD9"},{"hex":"#98A349"},{"hex":"#798616"}]但输出ng:repeat什么都不显示.所以json被加载到范围内但由于某种原因我不能遍历它.
这是我的主要js文件:
app.js
var App = angular.module('App', []).
config(function($routeProvider)
{
$routeProvider.
when('/palette', {templateUrl:'templates/palette.html', controller:PaletteController}).
otherwise({redirectTo:'/home'})
});
function PaletteController($scope, $http){
$http.get('palette.json').success(function(palette){
$scope.palette = palette;
});
}
Run Code Online (Sandbox Code Playgroud)
以及从json文件加载的数据:
palette.json
[
{"hex": "#6e4516"},
{"hex": "#DDDABE"},
{"hex": "#ECEAD9"},
{"hex": "#98A349"},
{"hex": "#798616"}
]
Run Code Online (Sandbox Code Playgroud)