单击事件时 jQuery 的 Smarty 输入字段中的动态主机名
Dynamic hostname in Smarty input field with jQuery on click event
目前我正在尝试创建一个带有 jQuery 单击事件的动态主机名。到目前为止我有这个
聪明:
<div>
<input class="hostname-box" type="text" name="domain" required="" value="">
<a href="#host" class="button">Add</a>
</div>
<div>
<a href="#submit" class="button">Order</a>
</div>
jQuery:
$('.button').click(function(){
var jHostName = $('.hostname-box');
var hostNameValue = jHostName.text().trim();
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
if(hostNameValue === '') {
jHostName.val(text+".hostname.local");
}
});
我可以像 random.hostname.local 这样在点击时生成文本。但目标是实现生成像vps{random}-{currentDate}.hostname.local这样的文本。
像这样?
var hostNameValue = '';
var text = "vps-";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 5; i++ ) {text += possible.charAt(Math.floor(Math.random() * possible.length));}
let date = new Date();
text += '-'+date.toISOString().substr(0,10);
if(hostNameValue === '') {
console.log(text+'.hostname.local');
}
目前我正在尝试创建一个带有 jQuery 单击事件的动态主机名。到目前为止我有这个
聪明:
<div>
<input class="hostname-box" type="text" name="domain" required="" value="">
<a href="#host" class="button">Add</a>
</div>
<div>
<a href="#submit" class="button">Order</a>
</div>
jQuery:
$('.button').click(function(){
var jHostName = $('.hostname-box');
var hostNameValue = jHostName.text().trim();
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
if(hostNameValue === '') {
jHostName.val(text+".hostname.local");
}
});
我可以像 random.hostname.local 这样在点击时生成文本。但目标是实现生成像vps{random}-{currentDate}.hostname.local这样的文本。
像这样?
var hostNameValue = '';
var text = "vps-";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 5; i++ ) {text += possible.charAt(Math.floor(Math.random() * possible.length));}
let date = new Date();
text += '-'+date.toISOString().substr(0,10);
if(hostNameValue === '') {
console.log(text+'.hostname.local');
}