我有以下JavaScript代码:
var ans_el = document.createElement( 'input' );
ans_el.setAttribute( 'id', unique_int_value );
ans_el.setAttribute( 'type', 'radio' );
ans_el.setAttribute( 'name', 'group' );
ans_el.setAttribute( 'value', 'myValue' );
ans_el.onclick = myFunction( this.id, this.value );
// Add ans_el to DOM.
function myFunction( index, value ) { // do something }
Run Code Online (Sandbox Code Playgroud)
当然,这不符合预期.至少在Firefox 3.6中没有.会发生什么事是的onclick创建元素并传递给参数时,事件被触发myFunction的是空的.将元素添加到DOM后,选择单选按钮时不会触发onclick事件.
如果有人对这里发生的事情有所了解,和/或如何动态添加事件处理程序,我将不胜感激.
class Response<T>
{ ... }
Response response = new Response();
Run Code Online (Sandbox Code Playgroud)
上面的代码编译.我不明白隐含的是什么.编译器不应该要求'T'的类型规范吗?例如以下内容:
Response<String> response = new Response<String>();
Run Code Online (Sandbox Code Playgroud)