将Javascript语句放在android上的Javascript接口方法调用之前时未执行
在android上调用javascript接口方法之前,我试图使用jquery更改按钮的文本。但是这个语句没有被执行。这是代码将Javascript语句放在android上的Javascript接口方法调用之前时未执行,javascript,android,jquery,Javascript,Android,Jquery,在android上调用javascript接口方法之前,我试图使用jquery更改按钮的文本。但是这个语句没有被执行。这是代码 $("#send_btn").click(function() { if(sendto_number_flag == 1 && sendto_msg_flag ==1 ) { $(this).html("Sending..."); //above statement gets executed after the
$("#send_btn").click(function() {
if(sendto_number_flag == 1 && sendto_msg_flag ==1 ) {
$(this).html("Sending...");
//above statement gets executed after the Java.sendSMS gets executed.
//I have tried with other statements like .addClass() .hide(), nothing works
var output = Java.sendSMS($("#sendto_number").val(), $("#sendto_msg").val());
//above statement executes fine and returns valid data
if(output == "true") {
$(this).html("Sent Successfully");
}
else if(output == "Network Error"){
$(this).html("Check Connection and Retry");
}
else {
$(this).html("Check Details and Retry");
}
}
});
HTML标记
<button type="button" class="button button_red" id="send_btn" value="Send">Send</button>
发送
尝试为java.sendSMS
呼叫添加一些延迟。像这样的
$("#send_btn").click(function() {
if(sendto_number_flag == 1 && sendto_msg_flag ==1 ) {
$(this).html("Sending...");
//above statement gets executed after the Java.sendSMS gets executed.
//I have tried with other statements like .addClass() .hide(), nothing works
var Variables = {};
Variables.$obj = $(this);
Variables.ResizeTimer = setTimeout(
function(){
var output = Java.sendSMS($("#sendto_number").val(), $("#sendto_msg").val());
//above statement executes fine and returns valid data
if(output == "true") {
$(Variables.$obj).html("Sent Successfully");
}
else if(output == "Network Error"){
$(Variables.$obj).html("Check Connection and Retry");
}
else {
$(Variables.$obj).html("Check Details and Retry");
}
},1000);
}
});
您何时注册单击处理程序?该按钮是否已在HTML中,还是稍后将动态添加?如果没有,请尝试('click',function(){…})上的
$(“#send_btn”)代码>这很有效,谢谢!尽管我在前面使用jquery.delay()进行了测试。