输入数字后,我必须自动聚焦下一个输入元素。
我的HTML:
public static void Main(string[] args)
{
Task.WaitAll(IntegrateWithSlackAsync());
}
private static async Task IntegrateWithSlackAsync()
{
var webhookUrl = new Uri("https://hooks.slack.com/services/TmyHook");
var slackClient = new SlackClient(webhookUrl);
while (true)
{
Console.Write("Type a message: ");
var message = Console.ReadLine();
Payload testMessage = new Payload(message);
var response = await slackClient.SendMessageAsync(testMessage);
var isValid = response.IsSuccessStatusCode ? "valid" : "invalid";
Console.WriteLine($"Received {isValid} response.");
Console.WriteLine(response);
}
}
}
}
public class SlackClient
{
private readonly Uri _webhookUrl;
private readonly HttpClient _httpClient = new HttpClient {};
public SlackClient(Uri webhookUrl)
{
_webhookUrl = webhookUrl;
}
public async Task<HttpResponseMessage> SendMessageAsync(Payload payload)
{
var serializedPayload = JsonConvert.SerializeObject(payload);
var stringCont = new StringContent(serializedPayload, Encoding.UTF8, "application/x-www-form-urlencoded");
var response = await _httpClient.PostAsync(_webhookUrl, stringCont);
return response;
}
}
}
在我的JavaScript中,我有:
public class Payload
{
public string token = "my token stands here";
public string user = "my userID";
public string channel = "channelID";
public string text = null;
public bool as_user = true;
public Payload(string message)
{
text = message;
}
}
这实际上可以正常工作,事情是当我试图在手机上使用它时,它保持在相同的输入状态,而不会转到下一个。我真的需要帮助。
谢谢!
答案 0 :(得分:0)
在触发keyup
事件之前,手机的浏览器未在input元素内接收值。因此if ($(this).val())
目前为假。您需要使用其他事件类型(例如input
)来避免这种情况。
更多信息和游乐场:
https://www.w3schools.com/jsref/event_onchange.asp
$('.inp-num').on('input', function() {
if ($(this).val()) {
$(this).next().focus();
}
});