动态文本框水印删除按键消息
我的树中有一个文本框,它是在运行时生成的,用于让用户在文本框中输入节点我已经给出了水标记消息,以在文本框的单击功能上输入一些内容我已经清除了文本框,但在按键事件我也希望清除文本,但无法做到这一点,我已经粘贴了我的代码
function CreateTextBoxNode(SpnPrntId) {
var elem = document.createElement("input");
elem.type = "text";
elem.id = "txtParent";
elem.value = "Enter node name";
$(elem).css("color", "DarkGray");
elem.setAttribute('onblur', 'SetSpanValueForParent("' + SpnPrntId + '")');
$(elem).keypress(function(e) {
SetEnterValue(SpnPrntId, e);
});
$(elem).click(function() {
textClick();
});
$(elem).focus(function() {
textClick();
});
return elem;
}
function SetEnterValue(prntID, e) {
var key = checkBrowser(e);
if (key == 13) {
SetSpanValueForParent(prntID);
}
}
function textClick() { $("#txtParent").val(''); 。
当按下回车键时,我必须将值附加到某个范围内,我也尝试了它的焦点功能,因此当文本框第一次带有焦点设置时,它会删除消息
i have a text-box in my tree that is generated run-time for giving the user to enter the node in the textbox i have given a water-marker message to enter something on the click function of textbox i have cleared the textbox but on the key press event also i want the text to be cleared but not able to do it i have pasted my code
function CreateTextBoxNode(SpnPrntId) {
var elem = document.createElement("input");
elem.type = "text";
elem.id = "txtParent";
elem.value = "Enter node name";
$(elem).css("color", "DarkGray");
elem.setAttribute('onblur', 'SetSpanValueForParent("' + SpnPrntId + '")');
$(elem).keypress(function(e) {
SetEnterValue(SpnPrntId, e);
});
$(elem).click(function() {
textClick();
});
$(elem).focus(function() {
textClick();
});
return elem;
}
function SetEnterValue(prntID, e) {
var key = checkBrowser(e);
if (key == 13) {
SetSpanValueForParent(prntID);
}
}
function textClick() {
$("#txtParent").val('');
}
On key press when enter is pressed i have to append the value into some span i also tried its focus function so when the first time the textbox come with focused set it removes the message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为使用 占位符 会更容易,它可以在许多现代浏览器(Firefox 、Chrome 等),然后可能是 jquery 插件 使其能够与不兼容的浏览器。
这是另一个非常简单的版本
https://github.com/brandonweiss/jquery-placeholder
我在我的项目中使用了这种方法网络应用程序,效果很好。最好的部分是它的可重用性。每次您需要水印时,只需将占位符标记添加到您的输入中即可完成。
I think it would be a lot easier for you to use a placeholder which will work in many modern browsers (Firefox, Chrome, Etc), and then maybe a jquery plugin to make it work with the incompatible browsers.
Here's another really simple version
https://github.com/brandonweiss/jquery-placeholder
I've used this approach in my web apps and it works great. The best part is the reusability of it. Every time you need a watermark, you simply add the placeholder tag to your input and you're done.