我有两个名为txtA的文本框,txtB
var count;//which needs to be compared with BValue
var AValue = $("#txtA").val();
var BValue = $("#txtB").val();
if (AValue == "") {
alert("Enter AValue and continue");
} else if (BValue == "") {
alert("Enter To BValue and continue");
} else if (AValue > BValue ) {
alert("AValue should be lesser than To BValue");
} else if (AValue == "" || BValue == "") {
alert("Please enter the AValue and BValue to continue");
} else if (AValue == "0") {
alert("Invalid AValue");
} else if (BValue > count) {
alert("Invalid BValue");
} else {
// do some operations here
}
所有条件都顺利通过,但BValue > count
虽然符合条件<{p>}但却触发了我
答案 0 :(得分:1)
使用:
if ( AValue == ""){
}
或者
if ( ($("#txtA").val()) == "" ){
}
答案 1 :(得分:0)
检查此工作示例。
package com.example.asad.save_photo;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.net.Uri;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageMetadata;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import java.io.ByteArrayOutputStream;
import java.io.File;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference storageRef = storage.getReferenceFromUrl("gs://savephoto-a1cc3.appspot.com");
final StorageReference mountainsRef = storageRef.child("images");
Button butt = (Button) findViewById(R.id.button);
butt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ImageView imageView = (ImageView) findViewById(R.id.image);
imageView.setImageResource(R.drawable.back2);
imageView.setImageResource(R.drawable.back2);
imageView.setDrawingCacheEnabled(true);
imageView.buildDrawingCache();
Bitmap bitmap = imageView.getDrawingCache();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] data = baos.toByteArray();
UploadTask uploadTask = mountainsRef.putBytes(data);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle unsuccessful uploads
showToast("unsuccessful");
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
//Uri downloadUrl = taskSnapshot.getDownloadUrl();
showToast("success !!!!!");
}
});
}
});
}
public void showToast(String s) {
Toast.makeText(this,s,Toast.LENGTH_SHORT).show();
}
}