考虑以下代码:
<input type="text" value="hello" id="hello" />
&#13;
baseurl
&#13;
围绕它的想法是让用户专注于输入,直到他/她输入有效文本。这是代码的简化版本。
Js在这里小提琴:https://jsfiddle.net/wzwft49w/9/
问题:如果你专注于输入然后模糊它,你将在Chrome中获得无限警报弹出窗口,但不会在IE中显示。
1。你会如何解决这个问题?
2。关于为什么会发生这种情况的任何想法?
注意:
答案 0 :(得分:2)
这是我的chrome解决方案:
@Html.DropDownListFor(m => m.itemId, Model.itemList, new Dictionary<string, object>()
{
{ "class", "form-control" },
{ "required", String.Empty },
{ "maxlength", "4" },
{ "minlength", "2" },
{ "[(ngModel)]", "dataForm.itemId" }
})
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim IntItemID As Integer
Dim siteId As Guid = SPContext.Current.Site.ID
Dim webId As Guid = SPContext.Current.Web.ID
Using objSpSite As New SPSite(siteId)
Using objSpWeb As SPWeb = objSpSite.OpenWeb(webId)
If Not Page.Request.QueryString("ItemID") Is Nothing And Page.Request.QueryString("ItemID") <> "" Then
IntItemID = CInt(Page.Request.QueryString.Item("ItemID").ToString)
Panel1.Visible = False
txtID.Text = IntItemID.ToString
Dim objList As SPList = objSpWeb.Lists("RequestList")
Dim objListItem As SPListItem = objList.Items.GetItemById(IntItemID)
dtPermission.SelectedDate = objListItem("PermissionDate")
dtTimeFrom.SelectedDate = objListItem("PermissionFromTime")
dtTimeTo.SelectedDate = objListItem("PermissionToTime")
cmbType.SelectedValue = objListItem("PermissionType")
'dtCreated.SelectedDate = objListItem("")
Else
IntItemID = 0
txtID.Text = "New"
dtCreated.SelectedDate = Today
txtCreatedBy.Text = objSpWeb.CurrentUser.Name
Dim objServiceContext As SPServiceContext = SPServiceContext.GetContext(objSpSite)
Dim objUserProfileManager As New UserProfileManager(objServiceContext)
Dim objUserProfile As UserProfile
Dim strUserAccount As String
strUserAccount = objSpWeb.CurrentUser.LoginName.Replace("i:0#.w|", "")
If objUserProfileManager.UserExists(strUserAccount) Then
objUserProfile = objUserProfileManager.GetUserProfile(strUserAccount)
Try
txtManager.Text = objUserProfile.GetManager.AccountName
Catch ex As Exception
txtManager.Text = ex.Message
End Try
End If
Panel2.Visible = False
End If
End Using
End Using
End Sub
Protected Sub cmdSubmit_Click(sender As Object, e As EventArgs) Handles cmdSubmit.Click
Dim siteId As Guid = SPContext.Current.Site.ID
Dim webId As Guid = SPContext.Current.Web.ID
Using objSpSite As New SPSite(siteId)
Using objSpWeb As SPWeb = objSpSite.OpenWeb(webId)
objSpWeb.AllowUnsafeUpdates = True
Dim list As SPList = objSpWeb.Lists("RequestList")
Dim item As SPListItem = list.Items.Add()
item("PermissionDate") = dtPermission.SelectedDate
item("PermissionFromTime") = dtTimeFrom.SelectedDate
item("PermissionToTime") = dtTimeTo.SelectedDate
item("PermissionType") = cmbType.SelectedValue
item("PermissionApprover1") = txtManager.Text
item.Update()
list.Update()
objSpWeb.AllowUnsafeUpdates = False
End Using
End Using
End Sub
Protected Sub cmdApprove_Click(sender As Object, e As EventArgs) Handles cmdApprove.Click
Dim siteId As Guid = SPContext.Current.Site.ID
Dim webId As Guid = SPContext.Current.Web.ID
Using objSpSite As New SPSite(siteId)
Using objSpWeb As SPWeb = objSpSite.OpenWeb(webId)
Dim objList As SPList = objSpWeb.Lists("RequestList")
Dim objListItem As SPListItem = objList.Items.GetItemById(CInt(txtID.Text))
Dim objWFTask As SPWorkflowTask = objListItem.Tasks(0)
If objWFTask Is Nothing Then
' no matching task
Return
End If
' alter the task
Dim ht As New Hashtable()
ht("Status") = "Complete"
ht("PercentComplete") = 1.0F
SPWorkflowTask.AlterTask(TryCast(objWFTask, SPListItem), ht, True)
End Using
End Using
var inputs = document.querySelectorAll("input"),
len = inputs.length,
i;
var gflag=false;
function myalert(m,o) {
if (gflag) {
return;
}
gflag=true;
alert(m);
o.focus();
setTimeout(function() {gflag=false;},10);
}
function makeBlurHandler() {
"use strict";
return function () {
if (this.value === "") {
myalert("Cannot be blank!",this);
this.nextElementSibling.innerHTML = "Cannot be blank!";
} else {
this.nextElementSibling.innerHTML = "";
}
};
}
for (i = 0; i < len; i++) {
inputs[i].addEventListener("blur", makeBlurHandler());
}
它也适用于IE,但由于focus()不适用于Firefox,因此无效。