本文介绍了建议的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我关于如何使用javazcript在按键事件期间突出显示文本框的建议吗?

Can any one tell me the suggestion on how to highlight the textbox during key press event using javazcript

推荐答案

<input type="button" runat="server" id="btnTest" onkeypress="HighLightTextBox()" />


function HighLightTextBox()
{
document.getElementById("textTextboxEditTemplate"+i).style.borderColor = "maroon" ;
}



如果要将相同的脚本应用于< asp:button>您可以将onkeypress作为属性添加到文件后面代码中的按钮上.



If you want to apply the same script to <asp:button> you can add the onkeypress as an Attributes to button in code behind file.



<script language="javascript">
    validateTextBox={
        init:function(){
            var box = document.getElementById('<%=txtBox.ClientID%>');
            box.onkeyup=validateTextBox.validate;
        },
        validate:function(e){
            var evt = e || window.event;
            var chr = evt.keyCode;
            var trget = evt.target || evt.srcElement;
            if((chr<96||chr>105)&&(chr<48||chr>57)){
                trget.style.backgroundColor = '#FF0000';
            }
            if(isNaN(trget.value)) {
                trget.style.backgroundColor = '#FF0000';
            }
            else{
                 trget.style.backgroundColor = '';
            }
        },
        addLoadEvent: function (func) {
            var oldonload = window.onload;
            if (typeof window.onload != 'function') {
                window.onload = func;
            }
            else {
                window.onload = function () {
                    oldonload();
                    func();
                }
            }
        }
    }
    validateTextBox.addLoadEvent(validateTextBox.init);
    </script>



< asp:textbox id ="txtBox" runat ="server">



<asp:textbox id="txtBox" runat="server">


这篇关于建议的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 04:11