将onkeyup添加到输入字段 [英] adding onkeyup to input field

查看:66
本文介绍了将onkeyup添加到输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个功能不起作用。我传递了td元素和

一个id,它在td中创建了一个输入字段。这部分工作。

什么是行不通的是我想添加一个onkeyup。在输入

字段。有帮助吗?请???我在Firefox中的javascript

控制台上没有任何错误,我在IE中没有看到任何错误。


//输入当模糊时它会使用setCalendarValue()

提交自己的字段(如果按下[enter]它将会模糊)

函数makeCalendarInputField(el,hoursId,which ){

var id = el.id;


//如果此输入字段已经激活,则不要让它为

再次激活

if(thisCalendarInputField == id){

返回false;

}

else {

thisCalendarInputField = id;

}

var value = el.innerHTML;

//记得原值以防万一

originalValue = value;

el.innerHTML ='''';

var inputField ="< input type =''text''value =''" + value +"''

name =''inputField''id =''inputField''"

+" onBlur =''setCalendarValue(this,\"" + id +" \");''

class =''calendarInputField''/>"

+"< input type =''hidden''name =''" + whichField +"''id =''" +

whichField +"''value =''" +其中+"''/>"

+"< input type =''hidden''name =''" + hoursIdField +"''id =''" +

hoursIdField +"''value =''" + hoursId +"''/>"

+"" ;;

//将此td的innerHTML更改为此输入字段

el.innerHTML = inputField;

document.getElementById(''inputField'')。focus();


el.onKeyUp =" ;警告(''hi'')" ;;


返回;

}

I have this function that doesn''t work. I pass it the td element and
an id, and it makes an input field inside the td. That part workds.
What doesn''t work is that I want to add an "onkeyup" on the input
field. Any help? Please??? I don''t get any error on my javascript
console in firefox, and I am not seeing any errors in IE.

// makes an input field that submits itself using setCalendarValue()
when it''s blurred (it will be blurred if [enter] is pressed)
function makeCalendarInputField(el,hoursId,which){
var id=el.id;

// if this input field is already active, then don''t let it be
activated again
if(thisCalendarInputField==id){
return false;
}
else{
thisCalendarInputField=id;
}
var value = el.innerHTML;
// remember the original value just in case
originalValue=value;
el.innerHTML='''';
var inputField = "<input type=''text'' value=''" + value + "''
name=''inputField'' id=''inputField'' "
+ " onBlur=''setCalendarValue(this,\"" + id + "\");''
class=''calendarInputField'' />"
+ "<input type=''hidden'' name=''" + whichField + "'' id=''" +
whichField + "'' value=''" + which + "'' />"
+ "<input type=''hidden'' name=''" + hoursIdField + "'' id=''" +
hoursIdField + "'' value=''" + hoursId + "'' />"
+ "";
// change the innerHTML of this td into this input field
el.innerHTML = inputField;
document.getElementById(''inputField'').focus();

el.onKeyUp="alert(''hi'')";

return;
}

推荐答案

Lee写道:
Lee wrote:

我有这个功能是行不通的。我传递了td元素和

一个id,它在td中创建了一个输入字段。这部分工作。

什么是行不通的是我想添加一个onkeyup。在输入

字段。有帮助吗?请???我在Firefox中的javascript

控制台上没有任何错误,我在IE中没有看到任何错误。


//输入当模糊时它会使用setCalendarValue()

提交自己的字段(如果按下[enter]它将会模糊)

函数makeCalendarInputField(el,hoursId,which ){

var id = el.id;


//如果此输入字段已经激活,则不要让它为

再次激活
I have this function that doesn''t work. I pass it the td element and
an id, and it makes an input field inside the td. That part workds.
What doesn''t work is that I want to add an "onkeyup" on the input
field. Any help? Please??? I don''t get any error on my javascript
console in firefox, and I am not seeing any errors in IE.

// makes an input field that submits itself using setCalendarValue()
when it''s blurred (it will be blurred if [enter] is pressed)
function makeCalendarInputField(el,hoursId,which){
var id=el.id;

// if this input field is already active, then don''t let it be
activated again



不允许发布的代码自动换行,它几乎总是会引入更多

错误。手动将代码包装为大约70个字符并使用2个空格进行

缩进,而不是制表符。

Do not allow posted code to auto-wrap, it nearly always introduces more
errors. Manually wrap code at about 70 characters and use 2 spaces for
indents, not tabs.


if(thisCalendarInputField == id){
if(thisCalendarInputField==id){



我猜 - thisCalendarInputField的值 - 在别处设置。

I guess the value of - thisCalendarInputField - is set elsewhere.


return false;

}

else {
return false;
}
else{



有条件退货后无需其他。

There is no need for an else after a conditional return.


thisCalendarInputField = id;

}

var value = el.innerHTML;

/ /记住原值以防万一

originalValue = value;

el.innerHTML ='''';

var inputField =" < input type =''text''value =''" + value +"''

name =''inputField''id =''inputField''"

+" onBlur =''setCalendarValue(this,\"" + id +" \");''

class =''calendarInputField''/>"
thisCalendarInputField=id;
}
var value = el.innerHTML;
// remember the original value just in case
originalValue=value;
el.innerHTML='''';
var inputField = "<input type=''text'' value=''" + value + "''
name=''inputField'' id=''inputField'' "
+ " onBlur=''setCalendarValue(this,\"" + id + "\");''
class=''calendarInputField'' />"



在源标记中使用混合大小写的属性名称是一个糟糕的b / b $ b习惯,使用全小写(即使HTML没有关心案例。


您的标签语法表示XHTML,但您的属性名称显示为

需要HTML。如果innerHTML也使用了HTML(尽管

没有标准来表明这是否是一个合理的推断

)。


使用HTML 4.01,在

网页上使用XHTML没有实际好处。

The use of mixed-case attribute names in the source markup is a bad
habit, use all lower case (even though HTML doesn''t care about case).

Your tag syntax indicates XHTML, but your attribute names appear to
require HTML. The use if innerHTML also infers the use of HTML (though
there is no standard to indicate whether that is a reasonable inference
or not).

Use HTML 4.01, there are no practical benefits to using XHTML on the
web.


+"< ; input type =''hidden''name =''" + whichField +"''id =''" +

whichField +"''value =''" +其中+"''/>"

+"< input type =''hidden''name =''" + hoursIdField +"''id =''" +

hoursIdField +"''value =''" + hoursId +"''/>"

+"" ;;

//将此td的innerHTML更改为此输入字段

el.innerHTML = inputField;

document.getElementById(''inputField'')。focus();


el.onKeyUp =" ;警报( HI)英寸;
+ "<input type=''hidden'' name=''" + whichField + "'' id=''" +
whichField + "'' value=''" + which + "'' />"
+ "<input type=''hidden'' name=''" + hoursIdField + "'' id=''" +
hoursIdField + "'' value=''" + hoursId + "'' />"
+ "";
// change the innerHTML of this td into this input field
el.innerHTML = inputField;
document.getElementById(''inputField'').focus();

el.onKeyUp="alert(''hi'')";



Javascript区分大小写:


el.onkeyup =" alert(''hi'')" ;;


使用所有小写属性名称(以及标签名称)是一个很好的习惯,特别是如果你真的打算使用XHTML。

-

Rob

Javascript is case sensitive:

el.onkeyup = "alert(''hi'')";

The use of all lower case attribute names (and tag names too) is a good
habit to get into, especially if you really do intend to use XHTML.
--
Rob


不允许发布的代码自动换行,它几乎总是引入更多
Do not allow posted code to auto-wrap, it nearly always introduces more

错误。手动将代码包装为大约70个字符并使用2个空格进行

缩进,而不是制表符。
errors. Manually wrap code at about 70 characters and use 2 spaces for
indents, not tabs.



ok我希望我没有包装,因为我非常感谢

帮助。我已经改变了一些东西,因为我已经理解了它们(我真的不会理解XHTML / HTML,所以我希望它除了这一点之外)。在我改变了函数之后,它仍然可以正常工作。


我意识到我没有使用正确的元素onkeyup,但它的价格仍然无法正常工作。仍然没有javascript错误。任何进一步的帮助是

真的很感激。感谢目前为止所做的一切!


//在模糊时使用

// setCalendarValue()创建一个输入字段(它会如果[输入]
按下
则会模糊。

函数makeCalendarInputField(el,hoursId,which){

var id = el.id;


//如果此输入字段已经激活,

//那么就不要让它再次激活

if(thisCalendarInputField == id){

返回false;

}

thisCalendarInputField = id;

var value = el.innerHTML;

//记住原值以防万一

originalValue = value;

el.innerHTML ='''' ;

var inputField =

"< input type =''text''value =''" +值

+"''name =''inputField''id =''inputField''"

+" onblur =''setCalendarValue(this,\"" + id

+" \");''class =''calendarInputField''/>"

+"< input type =''hidden''name =''" + whichField

+"''id =''" + whichField +"''value =''" +其中+"''/>"

+"< input type =''hidden''name =''" + hoursIdField +"''id =''"

+ hoursIdField +"''value =''" + hoursId +"''/>"

+"" ;;

//将此td的innerHTML更改为此输入字段

el.innerHTML = inputField;


var inputEl = document.getElementById(''inputField'');

inputEl.focus();


inputEl.onkeyup =" alert(''hi'')" ;;


返回;

}

ok I hope I got it not wrapping, because I really do appreciate the
help. I''ve changed things as I''ve understood them (I really don''t
understand XHTML/HTML, so I hope it''s besides the point). After I
changed the function, it still works as always.

I realized I didn''t use the correct element for "onkeyup," but it''s
still not working. Still no javascript errors. Any further help is
really appreciated. Thanks on everything so far!

// makes an input field that submits itself using
// setCalendarValue() when it''s blurred (it will be blurred if [enter]
is pressed)
function makeCalendarInputField(el,hoursId,which){
var id=el.id;

// if this input field is already active,
// then don''t let it be activated again
if(thisCalendarInputField==id){
return false;
}
thisCalendarInputField=id;
var value = el.innerHTML;
// remember the original value just in case
originalValue=value;
el.innerHTML='''';
var inputField =
"<input type=''text'' value=''" + value
+ "'' name=''inputField'' id=''inputField'' "
+ " onblur=''setCalendarValue(this,\"" + id
+ "\");'' class=''calendarInputField'' />"
+ "<input type=''hidden'' name=''" + whichField
+ "'' id=''" + whichField + "'' value=''" + which + "'' />"
+ "<input type=''hidden'' name=''" + hoursIdField + "'' id=''"
+ hoursIdField + "'' value=''" + hoursId + "'' />"
+ "";
// change the innerHTML of this td into this input field
el.innerHTML = inputField;

var inputEl=document.getElementById(''inputField'');
inputEl.focus();

inputEl.onkeyup = "alert(''hi'')";

return;
}


顺便说一句,我将使用一个单独的库,以这种方式在

中添加onkeyup,而我我只是使用警报来测试

。该库在输入字段的其他地方完美地工作,当页面加载时已经定义了


By the way, I am going to use a separate library that adds onkeyup in
this fashion, and I''m just using alert to test things out in the
meantime. The library works perfectly elsewhere on an input field that
is already defined when the page loads.


这篇关于将onkeyup添加到输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆