我正在使用输入,并且想将其隐藏为字符串/ var,以便在单击按钮后在警报中将其打印出来。
我需要输入“ Forename:”以将“ onlcick”添加到“发送”按钮中。
警报只是调试器。而不是警报,我想使用一个功能。使用onclick="printPDF(foreName+' '' ' + da + '.' + mo + '.' + ye + '_' + h + ':' + m + ':' + s + '.pdf');
function startTime() {
var today = new Date();
var da = today.getDate();
var mo = today.getMonth() + 1;
var ye = today.getFullYear();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);
}
function checkTime(i) {
if (i < 10) {
i = "0" + i
}; // add zero in front of numbers < 10
return i;
}
<p>
<label>Forename:</label>
<input class="w3-input w3-white" id="some1" type="text" name="some1" value="asd" maxLength="200">
</p>
<button id="snbtn1" type="submit" class="w3-btn w3-green" onclick="alert(' ' + da + '.' + mo + '.' + ye + '_' + h + ':' + m + ':' + s + '.pdf');">send</button>
答案 0 :(得分:0)
您应该通过获取button元素并向其添加事件侦听器,将hive> select timestamp('2019-01-01 12:10:10.123456789','yyyy-MM-dd HH:mm:ss.SSSSSSSSS');
OK
2019-01-01 12:10:10.123456789
Time taken: 12.845 seconds, Fetched: 1 row(s)
代码放入javascript代码中的函数中。用与您在JavaScript代码中获得按钮相同的方式,您可以获得输入及其值:
onclick
var today = new Date();
var da = today.getDate();
var mo = today.getMonth()+1;
var ye = today.getFullYear();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
//m = checkTime(m);
//s = checkTime(s);
document.getElementById("snbtn1").addEventListener("click", function() { // Get the button and add an onclick event listener to it
alert(' ' + da + '.' + mo + '.' + ye + '_' + h + ':' + m + ':' + s + '.pdf');
alert(document.getElementById("some1").value); // Get the input by it's id and alert the value
});
https://developer.mozilla.org/he/docs/Web/API/Document/getElementById
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
答案 1 :(得分:0)
<script>
function startTime() {
var today = new Date();
var da = today.getDate();
var mo = today.getMonth()+1;
var ye = today.getFullYear();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);
var foreName = document.getElementById('some1').value;
alert(foreName+' ' + da + '.' + mo + '.' + ye + '_' + h + ':' + m + ':' + s + '.pdf');
}
function checkTime(i) {
if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10
return i;
}
</script>
<p>
<label>Forename:</label>
<input class="w3-input w3-white" id="some1" type="text" name="some1" value="asd" maxLength="200">
</p>
<button id="snbtn1" type="submit" class="w3-btn w3-green" onclick="startTime();">send</button>