[英]Add time to textarea after click button
When i click id=dodaj_godzine_button i want to add current time to id=formularz_wpis_tresc (as string) 当我单击id = dodaj_godzine_button时,我想将当前时间添加到id = formularz_wpis_tresc (作为字符串)
I made this but it's doesn't work. 我做了这个,但是没用。
$("#dodaj_godzine_button").click(function(){
var data = new Date();
var godzina = data.getHours();
var minuty = data.getMinutes();
var czas = godziny;
czas += ((minuty < 10) ? ":0" : ":");
$("#formularz_wpis_tresc").html("Godzina: " + czas + "\n");
});
Where i've made mistake? 我在哪里弄错了?
How about this: 这个怎么样:
$("#dodaj_godzine_button").click(function(){
var data = new Date();
var godzina = data.getHours();
var minuty = data.getMinutes();
minuty = ((minuty < 10) ? ":0" + minuty : ":" + minuty);
$("#formularz_wpis_tresc").html("Godzina: " + godzina + minuty + "\n");
});
what's the console log message you got if you take a look at the javascript console? 如果您查看javascript控制台,会收到什么控制台日志消息? try using 尝试使用
$("#formularz_wpis_tresc").val("Godzina: " + czas + "\n");
see if that works 看看是否可行
There where two bugs: 那里有两个错误:
1- czas should be equals to "godzina" instead of "godziny". 1- cza应等于“ godzina”而不是“ godziny”。
2- The right way to show the output is: 2-显示输出的正确方法是:
$("#formularz_wpis_tresc").html("Godzina: " + czas + minuty + "\n");
Two corrections should make it work: 两项更正应使其起作用:
First, change: 首先,更改:
var czas = godziny;
To: 至:
var czas = godzina;
as pointed out by @dfsq in the comments. 正如@dfsq在评论中指出的那样。 Then, change: 然后,更改:
$("#formularz_wpis_tresc").html("Godzina: " + czas + "\n");
To: 至:
$("#formularz_wpis_tresc").val("Godzina: " + czas + "\n");
as pointed out by @user2325727 , assuming this is the textarea
and the clicked element is the the button
. 如@ user2325727所指出的,假定这是textarea
,而clicked元素是button
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.