怎样才能使javascript提示框中的取消按钮不像确认框中的取消按钮那样做,而不是发送"null“值?
或者可以从提示框中删除cancel按钮,这样就只剩下"ok“按钮了?
这就是我所尝试的,但它仍然将null to值发送到我的PHP文件。
function AskQuestion(data)
{
var id = getUrlVars()["id"];
console.log(data);
if(data.key[0].status == "ok") {
var reply = prompt(data.key[0].REPLY, "");
var index = data.key[0].IND;
if(reply != "" && reply !== null) {
//do nothing
}else{
jQuery.ajax({ type: "POST",
url: serviceURL + "message.php",
data: 'id='+id+'&arvo='+reply+'&index='+index,
cache: false,
success: AskQuestion});
}
} else {
window.location = "page.html"
}
}发布于 2012-07-05 15:02:49
你对返回值的测试是错误的。因为它在用户输入文本时调用// do nothing,而在用户不输入文本时调用ajax。
if(reply != "" && reply !== null) {
// do nothing至
if(reply == null || jQuery.trim(reply).length == 0) {
// do nothing发布于 2012-07-05 14:52:11
以下是一些想法:
reply = jQuery.trim( prompt(...) || "" );
if( reply ){
jQuery.ajax(...)
}发布于 2012-07-05 14:50:55
您可以返回以退出函数
https://stackoverflow.com/questions/11339119
复制相似问题