在输入

时间:2015-09-16 17:19:35

标签: javascript php jquery ajax

我有一个带有自动完成输入字段的表单。当有3  输入中的字符会触发事件,我不希望这种情况发生。 输入具有onfocus=//do something参数。

我已经尝试event.preventDefault()stopPropagationreturn false但没有效果

1 个答案:

答案 0 :(得分:0)

这将删除输入的onFocus属性: package testers.jpa.beans; import java.io.Serializable; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.NamedQuery; import javax.persistence.Table; import javax.persistence.Transient; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @Entity @Table(name = "dbo.tester") //Ignore the actual calendar object here because the jsonner strips the timezone info from it @JsonIgnoreProperties(value = { "date" }) @NamedQuery(name = "NameAndOffset.purge", query = "DELETE FROM NameAndOffset") public class NameAndOffset implements Serializable { private static final long serialVersionUID = 1L; private String name; private Calendar date; public NameAndOffset() { } public NameAndOffset(String name, Calendar date) { this.name = name; this.date = date; } @Id @Basic public String getName() { return name; } public void setName(String name) { this.name = name; } /** * Return a string representation of the {@link NameAndOffset#date} object.<br/> * This will be used by JPA and the Jsonner to prevent losing the timezone * information<br/> * <br/> * For this to work properly you must tell both the Json mapper and JPA to * ignore anything else that relates to the {@link NameAndOffset#date} field * * @return A String representation of the {@link NameAndOffset#date} field, * formatted for SQL Server's datetimeoffset data type */ @Basic @Column(name = "date") public String getDateTimeOffset() { return new OffsetDateFormat().formatCalendar(date); } public void setDateTimeOffset(String date) throws ParseException { this.date = new OffsetDateFormat().parseCalendar(date); } //Ignore the actual calendar object here because JPA strips the timezone info from it @Transient public Calendar getDate() { return date; } public void setDate(Calendar date) throws ParseException { this.date = date; } class OffsetDateFormat extends SimpleDateFormat { private static final long serialVersionUID = 1L; private static final String OFFSET_FORMAT = "yyyy-MM-dd HH:mm:ss.S Z"; public OffsetDateFormat() { super(OFFSET_FORMAT); } public Calendar parseCalendar(String source) throws ParseException { //pull out the colon in the offset int timeZoneColon = source.lastIndexOf(":"); String nocolon = source.substring(0, timeZoneColon) + source.substring(timeZoneColon + 1); Calendar cal = Calendar.getInstance(); cal.setTime(parse(nocolon)); //after parsing, the timezone of this DateFormatter changes to whatever was represented in the string //make sure the new calendar reflects this cal.setTimeZone(getTimeZone()); return cal; } public String formatCalendar(Calendar calendar) { setTimeZone(calendar.getTimeZone()); String nocolon = format(calendar.getTime()); //add the colon StringBuffer sb = new StringBuffer(nocolon.substring(0, nocolon.length() - 2)).append(":").append(nocolon.substring(nocolon.length() - 2)); return sb.toString(); } } }