我的任务是在不使用任何库(如jQuery或原型)的情况下在文档上触发自定义事件.
所以我对Firefox这样做很好:
function fireCustomEvent(eventData)
{
if (document.createEvent) // Firefox
{
var event = document.createEvent('HTMLEvents'); // create event
event.initEvent('myCustomEvent', true, true ); // name event
event.data = eventData; // put my stuff on it
document.dispatchEvent(event); // fire event
}
else if (document.createEventObject) // IE
{
xxxxxxxxxxx
}
}
Run Code Online (Sandbox Code Playgroud)
现在我可以像这样开火:
fireCustomEvent({
category: 'test',
value: 123
});
Run Code Online (Sandbox Code Playgroud)
并像这样捕获它(这里我可以使用jQuery):
$(document).bind('myCustomEvent', function (event) {
doStuff(event);
});
Run Code Online (Sandbox Code Playgroud)
我的问题是,我可以做些什么来使这项工作在IE上(换句话说,我把xxxxxxxxxxx放在哪里)?
我认为IE等效应该看起来像这样:
var event = document.createEventObject();
event.data = eventData;
document.fireEvent('myCustomEvent', event);
Run Code Online (Sandbox Code Playgroud)
但这不起作用.IE让我只使用预定义的事件名称(onclick等),甚至其中一些不起作用(例如onmessage)
任何帮助或想法表示赞赏!
你能告诉我如何在Grails域类上进行投影吗?!在我的情况下,我想通过他们的ID得到(例如)用户名的列表.这意味着在我的方法中,我传递一个userId列表并获取用户名的列表.Groovy域的动态方法是否支持此功能?目前,我正在使用我的以下功能:
public String getUserNamesByIds(String[] ids) {
StringBuffer names = User.get(Integer.parseInt(ids[0]).getName())
if(ids.length > 1) {
(1..ids.length - 1).each{
names.append(", " + User.get(Integer.parseInt(ids[it])).getName())
}
}
return names.toString()
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我只想获取名称(并构建总字符串).我认为这不好,因为我必须做很多小步骤,并对数据库执行许多查询以获取User对象.有没有更好的方法来做到这一点?非常感谢!
通常,这一切都非常适合将我的对象序列化为Xml字符串并再次返回到对象中.但是,我有不同的最终用户之间的这种不一致,我似乎无法追查.
基本上,当我序列化一个对象时,它看起来像转换为Xml后:
<?xml version="1.0" encoding="utf-8"?>
<Step xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Name>Step 2</Name>
<VoltageDip>20</VoltageDip>
<Loads>
<Load xsi:type="ThreePhaseMotorLoad">
<Name>Motor 450 KW Pump</Name>
<Comments />
<Quantity>1</Quantity>
<Voltage>
<Name>400 Volt 3 Phase 12w 50Hz</Name>
<V3Id xsi:nil="true" />
<Value>400</Value>
<V3Value>415</V3Value>
<Connection>Wye</Connection>
<Phase>3</Phase>
<RangeDescription>231/400v</RangeDescription>
<VoltageCode>F</VoltageCode>
<Active>true</Active>
<Frequency>50</Frequency>
<PowerFactor>0.8000</PowerFactor>
<UL2200>false</UL2200>
<Default>false</Default>
<TempRiseIds>
<TempRiseId>F</TempRiseId>
</TempRiseIds>
</Voltage>
<IsNonLinear>true</IsNonLinear>
<PriorityProperty>KWm</PriorityProperty>
<KW>0</KW>
<RunningPowerFactor xsi:nil="true" />
<StartingPowerFactor>0.90</StartingPowerFactor>
<KWm>450</KWm>
<Efficiency xsi:nil="true" />
<IsLowInertia>false</IsLowInertia>
<MotorStandard>NEMA</MotorStandard>
<MotorStartingMethod>VariableFrequencyDrive</MotorStartingMethod>
<NEMAMotorCode>F</NEMAMotorCode>
<SolidStateStarterPercent>0</SolidStateStarterPercent>
<LockedRotorKVAPerHP>5.3</LockedRotorKVAPerHP>
</Load>
<Load xsi:type="ThreePhaseMotorLoad">
<Name>Motor 450 KW Pump</Name>
<Comments />
<Quantity>1</Quantity>
<Voltage>
<Name>400 Volt 3 Phase 12w 50Hz</Name> …Run Code Online (Sandbox Code Playgroud) 我正在为图像文件绘制标签.除了字体大小外,一切都很完美.
gfx.DrawString(
thisTempLabel.LabelText,
new System.Drawing.Font(
thisTempLabel.LabelFont,
(float)thisTempLabel.fontSize
),
Brushes.Black,
new PointF(thisTempLabel.x, thisTempLabel.y)
);
Run Code Online (Sandbox Code Playgroud)
问题是我的用户在PX中选择字体大小,并且System.Drawing.Font需要EM大小.我不知道怎么解决这个问题!
我可以使用像素渲染文字吗?
我有一个接受文件上传的servlet,我想将文件存储在磁盘上的特定目录中.我正在使用码头.文件系统如下所示:
/jetty
/bin
/contexts
/stuff
/webapps
foo.war // one web app
grok.war // another web app
start.jar
Run Code Online (Sandbox Code Playgroud)
我从start.jar文件启动jetty.在servlet的上下文中,我不确定如何将文件保存到我想要的目标,即"/ stuff"文件夹:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
File downloaded = new File("some/path/here/stuff"); // ?
}
Run Code Online (Sandbox Code Playgroud)
是的 - 我不确定使用什么路径 - 有没有办法我可以使用File类在java中打印当前的工作目录来解决这个问题?
谢谢
如何检查什么是Apache用户?
我需要为它提供读写权限,对于我的Web根目录和Web根目录之外的某些目录,我该怎么做?
由于我不清楚Apache用户是什么,我无法回答我的下一个问题.
我正在尝试阅读嵌入的文本文件,System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resource);但它给了我一个Stream.嵌入式资源是一个文本文件,那我怎么能把它Stream变成一个TextReader?
我的字符串是
a
b
c
d
Run Code Online (Sandbox Code Playgroud)
我想做这个
a b c d
Run Code Online (Sandbox Code Playgroud)
怎么样?
这应该是一个简单的,但通过我在网上完成的所有研究,我似乎无法找到解决方案!
我目前有一个使用.sortable的可排序列表,然后双击一个.bind事件,绑定事件如下:
$("#controlContainer").sortable({
blah blah
})
.bind('dblclick', function(event) {
alert($(event.eventData).attr('id'));
});
Run Code Online (Sandbox Code Playgroud)
我的问题是,上面的内容不起作用,我需要获取双击任何元素的ID,但无法找到访问它的方法.
任何有解决方案的人?非常感谢.
我有一个代码,它获取所有函数的列表以及函数在FooBar其参数消息上支持的正则表达式:
functionList = []
def notify(RegExpression):
def _notify(function):
functionList.append((RegExpression, function))
return function
return _notify
class FooBar:
@notify(".*")
def everything(self, message):
pass
@notify("(\w+):.*")
def reply(self, message):
pass
for foo in functionList:
print("%s => %s" % foo)
Run Code Online (Sandbox Code Playgroud)
我想做类似的事情,但将函数列表及其参数作为类变量放入类中。当FooBar存在更多类似的类时,它会防止出现问题。每个类都应该有自己的列表。
def notify(RegExpression):
# ???
class FooBar:
functionList = []
@notify(".*")
def everything(self, message):
pass
@notify("(\w+):.*")
def reply(self, message):
pass
for foo in FooBar.functionList:
print("%s => %s" % foo)
Run Code Online (Sandbox Code Playgroud)
投入什么notify()?