我正在使用“ numscroller.js”作为计数器,但出现2个JavaScript错误-“未捕获的TypeError:无法读取HTMLHeadingElement上未定义的属性'top'。” -- 第40行。
有人可以用下面的代码帮助我吗,它显示错误在第40行中?
任何帮助将不胜感激,谢谢您。
也是有效的网址-http://bluecrystaluae.com/counter/counter.html
package bi.anpr.layouts;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.text.InputFilter;
import android.text.Spanned;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.sxx.vlctest.R;
public class LimitedEditTextPreference extends Preference implements InputFilter {
private enum InputType {
integerOnly, decimalOnly;
}
private int lastSavedIntValue = -1;
private float min = 0, max = 100, dv = min, lastSavedDoubleValue = -1;
private String unit = "";
private InputType inputType = InputType.integerOnly;
private EditText editText;
private TextView txt_title, txt_summary, txt_unit;
private Context context_;
public LimitedEditTextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
context_ = context;
readAttributes(context, attrs, 0, 0);
}
public LimitedEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
context_ = context;
readAttributes(context, attrs, defStyleAttr, defStyleRes);
}
public void readAttributes(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
TypedArray attr = null;
if (defStyleAttr == -1)
attr = context.obtainStyledAttributes(R.styleable.LimitedEditTextPreference);
else
attr = context.obtainStyledAttributes(attrs, R.styleable.LimitedEditTextPreference, defStyleAttr, defStyleRes);
int type = attr.getInt(R.styleable.LimitedEditTextPreference_lep_type, 0);
if (type == 1)
inputType = InputType.decimalOnly;
min = attr.getFloat(R.styleable.LimitedEditTextPreference_lep_minValue, 0);
max = attr.getFloat(R.styleable.LimitedEditTextPreference_lep_maxValue, 100);
unit = attr.getString(R.styleable.LimitedEditTextPreference_lep_unit);
TypedArray defaltValAttr = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.defaultValue});
dv = defaltValAttr.getFloat(0, min);
attr.recycle();
defaltValAttr.recycle();
}
@Override
protected synchronized View onCreateView(ViewGroup parent) {
super.onCreateView(parent);
SharedPreferences sharedPref = context_.getSharedPreferences(getKey(), Context.MODE_PRIVATE);
View v = initViews(parent);
txt_title.setText(getTitle());
txt_unit.setText(unit);
if (getSummary() != null && getSummary().toString().trim().length() > 1)
txt_summary.setText(getSummary());
else {
txt_summary.setText("");
txt_summary.setTextSize(0);
}
if (inputType == InputType.integerOnly) {
lastSavedIntValue = sharedPref.getInt(getKey(), (int) dv);
editText.setText(String.valueOf(lastSavedIntValue));
} else if (inputType == InputType.decimalOnly) {
lastSavedDoubleValue = sharedPref.getFloat(getKey(), dv);
editText.setText(String.valueOf(lastSavedDoubleValue));
}
editText.setFilters(new InputFilter[]{this});
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
String val = editText.getText().toString();
if (!TextUtils.isEmpty(val)) {
if (inputType == InputType.integerOnly) {
if (Integer.valueOf(val) < min) {
Toast.makeText(context_, getTitle() + ": Accepted input Range = [" + min + ", " + max + "]", Toast.LENGTH_SHORT).show();
editText.setText(String.valueOf(lastSavedIntValue));
editText.clearFocus();
return;
} else
savePref(Integer.valueOf(val));
} else if (inputType == InputType.decimalOnly)
if (Float.valueOf(val) < min) {
Toast.makeText(context_, getTitle() + ": Accepted input Range = [" + min + ", " + max + "]", Toast.LENGTH_SHORT).show();
editText.setText(String.valueOf(lastSavedDoubleValue));
editText.clearFocus();
return;
} else
savePref(Float.valueOf(val));
}
}
});
return v;
}
@Override
public void notifyDependencyChange(boolean disableDependents) {
super.notifyDependencyChange(disableDependents);
notifyChanged();
}
private View initViews(ViewGroup parent) {
LayoutInflater li = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = li.inflate(R.layout.limited_edittextpreference_view, parent, false);
if (editText != null)
return v;
editText = v.findViewById(R.id.txt_lep_edit);
txt_title = v.findViewById(R.id.txt_lep_title);
txt_summary = v.findViewById(R.id.txt_lep_summary);
txt_unit = v.findViewById(R.id.txt_lep_unit);
return v;
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
view.setClickable(true);
view.setFocusable(false);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
editText.requestFocus();
InputMethodManager imm = (InputMethodManager) context_.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}
});
}
public void savePref(Number number) {
SharedPreferences sharedPref = context_.getSharedPreferences(getKey(), Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
if (inputType == InputType.integerOnly) {
editor.putInt(getKey(), number.intValue());
lastSavedIntValue = number.intValue();
} else if (inputType == InputType.decimalOnly) {
editor.putFloat(getKey(), number.floatValue());
lastSavedDoubleValue = number.floatValue();
}
editor.commit();
}
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
try {
String replacement = source.subSequence(start, end).toString();
String newVal = dest.toString().substring(0, dstart) + replacement + dest.toString().substring(dend, dest.toString().length());
if (newVal.equalsIgnoreCase("-")) return null;
if (inputType == InputType.integerOnly) {
int input = Integer.parseInt(newVal);
if (input <= max)
return null;
} else if (inputType == InputType.decimalOnly) {
double input = Float.parseFloat(newVal);
if (input <= max)
return null;
}
} catch (NumberFormatException nfe) {
}
return "";
}
}