我想在加载图像时将图像父级的大小调整为相同大小的图像.
这时候我正在使用这段代码:
$(window).load(function(){
$('.image-principale').each(function(){
$(this).parent().css('height', $(this).height());
});
});
Run Code Online (Sandbox Code Playgroud)
它工作,除了它只在每个图像加载时运行.我试图直接为每个图像添加一个加载处理程序,但它们不会触发.
怎么了?
谢谢!
是否可以注册将在javascript错误或异常发生时执行的错误或异常处理程序/函数?我只是觉得将所有代码包装在try/catch块中似乎非常繁琐且效率低下.
我有一个错误"无法从类型处理程序中对非静态方法sendEmptyMessage(int)进行静态引用"
怎么解决?我认为这是一个问题,我这样做的课程不是一项活动?
new Thread() {
public void run() {
try {
List<Sail> sails = searchSails();
selectSailIntent.putParcelableArrayListExtra(
Constant.SAILS, new ArrayList<Sail>(sails));
getContext().startActivity(selectSailIntent);
Handler.sendEmptyMessage(0);
} catch (Exception e) {
alertDialog.setMessage(e.getMessage());
Handler.sendEmptyMessage(1);
}
}
}.start();
}
};
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我有录制按钮.我希望当用户每一次点击它时我会改变背景以模拟闪烁.我创建了一个处理程序并将其设置为1秒,因此每个处理程序运行一秒钟.在这里我改变了背景.我的代码:
mUpdateUITimerTask = new Runnable() {
public void run() {
// Simulating blinking for capture button
if(bolToggle) {
bolToggle = false;
captureButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_record_blink));
} else {
bolToggle = true;
captureButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_record));
}
mHandler.postDelayed(mUpdateUITimerTask, 1000);
}
};
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,我看到了更改,但不清楚.按钮是这样的:

当我运行应用程序时,红色图像显示正常,但对于白色图像,它显示红色图像,周围有一点白色光环.我尝试captureButton.setBackgroundColor(Color.TRANSPARENT);在设置背景之前放置,但结果是相同的.
任何建议将不胜感激.谢谢.
所有:
我真的不是grok处理程序了.我认为下面的代码 - 修改,以便,而不是使用处理程序,直接访问UI小部件(进度条) - 将导致跨线程异常.但事实并非如此.所以,我的问题是,这段代码不应该崩溃吗?如果没有,那么我什么时候需要使用处理程序?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
progress = 0;
progressBar = (ProgressBar) findViewById(R.id.progressbar);
progressBar.setMax(200);
//---do some work in background thread---
new Thread(new Runnable()
{
public void run()
{
//ó-do some work hereó-
while (progressStatus < 200)
{
progressStatus = doSomeWork();
progressBar.setProgress(progressStatus); // not on UI thread
//ó-Update the progress baró- // so shouldn't it crash?
// handler.post(new Runnable()
// {
// public void run() {
// progressBar.setProgress(progressStatus);
// }
// });
}
//---hides …Run Code Online (Sandbox Code Playgroud) 我尝试打开页面时遇到异常:
发生未处理的异常,并终止该过程.
应用ID:/ LM/W3SVC/6/ROOT/ROXY/es
进程ID:2972
例外:System.InvalidOperationException
消息:句柄未初始化.
堆栈跟踪:
在System.WeakReference.set_Target(对象的值)
在System.Data.ProviderBase.DbConnectionInternal.CloseConnection(的DbConnection owningObject,DbConnectionFactory connectionFactory的)
在System.Data.Odbc.OdbcConnection.Close()
在DsNet.CUIHandler.CloseConn()
在DsNet.CUIHandler.Finalize()
在页面中我得到错误:
消息:调用的目标抛出了异常.
任何的想法?
提前致谢
假设您需要编写一个带有一个attribute-parameter - 控制器事件函数名称的指令.该指令执行一些处理,然后在该事件处理程序上触发通知,并向其传递一些处理参数.
在指令中设置此类属性的建议方法是什么,以避免不必要的开销,如双向绑定?
到目前为止,我只能通过使用双向绑定来实现这一点,如下例所示:
app.controller("testCtrl", function ($scope) {
$scope.onClickEvent = function (ctrlDown) {
alert(ctrlDown);
}
});
app.directive("customInput", function () {
return {
restrict: "E",
scope: {
onClickNotify: "=onClick",
},
template: "<input type='text' ng-click='onClick()' />",
replace: true,
transclude: false,
link: function (scope, element, attrs, controller) {
scope.onClick = function () {
if (typeof (scope.onClickNotify) == 'function') {
scope.onClickNotify(window.event.ctrlKey);
}
}
}
}
});
<custom-input on-click="onClickEvent" />
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,该指令使用"=" - 属性的双向绑定,这是我能够使它工作的唯一方法.我无法理解的是为什么我们不能使用"&"?根据AngularJS文档,我们应该能够在传递带名称的参数时,例如:
scope.onClickNotify({ctrlDown: window.event.ctrlKey});
Run Code Online (Sandbox Code Playgroud)
但它只是不起作用.如果我尝试在事件名称中指定参数,如下所示:
<custom-input on-click="onClickEvent(ctrlDown)" />
Run Code Online (Sandbox Code Playgroud)
然后它仍然无法正常工作.相反,我在指令中传递的值将被忽略.
我对背景中真正发生的事情感到困惑,为什么不按预期使用"&"?在这种情况下,双向绑定看起来像是一个开销,因为我们只是在一个方向传递函数名称,如果不是作为一个简单属性(使用"@").
如果我在这里做错了什么,那么正确的方法是什么?
目前正在尝试使用Python中的Google App Engine创建基本博客.这是我正在使用的python代码:
import os
import re
import webapp2
import jinja2
from string import letters
from google.appengine.ext import db
template_dir = os.path.join(os.path.dirname(__file__), 'templates')
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir), autoescape=True)
class Handler(webapp2.RequestHandler):
def write(self, *a, **kw):
self.response.out.write(*a, **kw)
def render_str(self, template, **params):
t = jinja_env.get_template(template)
return t.render(params)
def render(self, template, **kw):
self.write(self.render_str(template, **kw))
def post_key(name = "dad"):
return db.Key.from_path('blog', name)
class Blogger(db.Model):
name = db.StringProperty()
content = db.TextProperty()
created = db.DateTimeProperty(auto_now_add = True)
def render(self):
self._render_text = self.content.replace('\n', '<br>')
return render_str("post.html", …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的SOAP客户端,我在wsimport实用程序的帮助下创建了我自己的Web服务.客户端工作原理非常好,但是当我添加一个处理程序时,它会中断.下面是我的工作客户端,它向控制台打印'1'...
public class MyFirstSoapClient {
public static void main(String args[]) {
SuperSimpleServiceService sib = new SuperSimpleServiceService();
ServiceEndpointInterface sei = sib.getSuperSimpleServicePort();
System.out.println(sei.return1());
}
}
Run Code Online (Sandbox Code Playgroud)
现在对于有趣的部分,这里是与处理程序实现相同的客户端,后跟输出...
public class MyFirstSoapClient {
public static void main(String args[]) {
SuperSimpleServiceService sib = new SuperSimpleServiceService();
sib.setHandlerResolver(new HandlerRegistration());
ServiceEndpointInterface sei = sib.getSuperSimpleServicePort();
System.out.println(sei.return1());
}
}
Run Code Online (Sandbox Code Playgroud)
产量
MyHandler: getHeaders
MyHandler: handleMessage
MyHandler: close
Exception in thread "main" com.sun.xml.internal.ws.streaming.XMLStreamReaderException: unexpected XML tag. expected: {http://interfaces.wsd.oce/}return1Response but found: {http://interfaces.wsd.oce/}return1
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.verifyTag(Unknown Source)
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.verifyTag(Unknown Source)
at com.sun.xml.internal.ws.client.sei.ResponseBuilder$DocLit.readResponse(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source) …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用Android Studio中的处理程序执行定时任务,但是当我尝试初始化它时,会发生这种情况:
private Handler handler = new Handler() {
@Override
public void publish(LogRecord record) {
}
@Override
public void flush() {
}
@Override
public void close() throws SecurityException {
}
};
Run Code Online (Sandbox Code Playgroud)
每当我查看人们使用Handler定期执行代码的在线示例时,它们的声明看起来如下:
private Handler handler = new Handler();
Run Code Online (Sandbox Code Playgroud)
如何避免处理程序中的大量方法?