javascript 输入的jQuery keyup值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11071394/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 12:01:06  来源:igfitidea点击:

jQuery keyup value of input

javascriptjquery

提问by Gabriel Uhlí?

i need to display value of <input>into the <span>and when label become empty, change value of span to "Video title". But always i type something into the <input>and then delete it, the <input>still have "" value so <span>display nothing. Thanks for help. (And sorry for my bad english)

我需要显示<input>into the 的值,<span>当标签变空时,将 span 的值更改为“视频标题”。但是我总是在里面输入一些东西<input>然后删除它,<input>仍然有“”值所以<span>什么都不显示。感谢帮助。(对不起,我的英语不好)

Here is my code:

这是我的代码:

$("#newVideoName").keyup(function(){
   var newVideoName = $("#newVideoName").val();
   if(newVideoName == ""){
       $("#newVideoNameLabel").html("Video title");
   }
});
<input type="text" id="newVideoName">
<span id="newVideoNameLabel"></span>

采纳答案by undefined

$("#newVideoName").keyup(function() {
   $("#newVideoNameLabel").text(this.value ? this.value : "Video title");
});

http://jsfiddle.net/gZPyQ/

http://jsfiddle.net/gZPyQ/