我可以防止"onblur"事件中的选择丢失吗?
<!DOCTYPE html>
<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "en" lang = "en">
<head>
<meta http-equiv = "Content-Type" content = "text/html; charset=utf-8">
<script type = "text/javascript">
window.onload = function () {
var textarea = document.getElementsByTagName ("textarea")[0];
textarea.onblur = function () {
alert ("Should keep selection");
return false;
}
}
</script>
<title>Select me !</title>
</head>
<body>
<textarea>Select me !</textarea>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
谢谢/
我可以使用 onBlur 来验证 type=text 或 textarea 输入,但是我无法对 type=file 进行相同的操作。
这有效:
<input type='text' name='sometextfield' size=30 class='input' onBlur="alert('Frell me dead, it works!');"
Run Code Online (Sandbox Code Playgroud)
这不会(没有错误):
<input type='file' name='file_upload' size=30 class='input' onBlur="alert('Frell me dead, it works!');">
Run Code Online (Sandbox Code Playgroud)
即时验证 type=file 输入框的技巧是什么?我想在香草 Javascript 中做到这一点。我正在 Ubuntu 下使用 Chrome 17.0.963.56 和 Firefox 10.0.2 进行测试。
感谢您的提示/指示。
我正在写一份联系表格.
我头部有两个Javascript函数(稍后会移动它们,但这是另一个问题).
Validate()onblur事件的第一个函数不起作用.第二个函数,formValidate()用于onsubmit事件.
我想在javascript函数中使用switch语句在html onblur事件中使用.
Javascript:
<head>
<script type="text/javascript">
function Validate()
{
// create array containing textbox elements
var input = [document.getElementById('fname'), document.getElementById('lname'), document.getElementById('email1'), document.getElementById('email12'), document.getElementById('message')];
for(var i = 0; i<input.length; i++)
// loop through each element to see if value is empty
{
if(input[i].value == '')
{
switch (ID){
case 'fname':
alert ('enter you first name');
break;
case 'lname' :
alert ('enter your last name');
break;
case 'email1':
alert ('enter your email address');
break;
case 'email2': …Run Code Online (Sandbox Code Playgroud) 我有一些文本输入字段,如果用户更改一个值,然后模糊远离该文本字段,js将触发和ajax请求更新数据库中的该值.问题是我写了一个测试来触发这样的事件,我注意到内部'blur'事件通常在我输出输入字段后触发两到五次:
$('input[type=text]').on('input propertychange paste', function() {
$(this).on('blur', function () {
console.log('blur');
});
});
Run Code Online (Sandbox Code Playgroud)
即使我在捕获后立即关闭模糊事件处理程序,它仍然会触发两到三次.我怎么才能让它只发生一次?
据我了解,onFocus单击输入框时应调用它,而onBlur当其他内容成为焦点时应调用它。
我的意图是:我想调用一个函数,当单击激活该函数时,它将.concat成为focuse中输入框的消息字符串,但是我无法使用onFocus或onBlur工作。
从我发现的搜索范围来看,这应该可以解决问题,但事实并非如此。
import React, { Component } from 'react'
class SocialPost extends Component {
state = {
message: this.props.socialPost.message,
focus: false
}
_onBlur() {
setTimeout(() => {
if (this.state.focus) {
this.setState({
focus: false,
});
}
}, 0);
}
_onFocus() {
if (!this.state.focus) {
this.setState({
focus: true,
});
}
}
render() {
return (
<div className='...'>
<div className='...'>
...
<input
onFocus={this._onFocus()}
onBlur={this._onBlur()}
type='text'
value={this.state.message}
onChange={...}/>
...
</div>
</div>
) …Run Code Online (Sandbox Code Playgroud) 我有一个带有 onfocus 和 onblur 事件的输入文本框。文本框下方是一个 div,通过 display: none 隐藏。
如果文本框获得焦点,则应显示 div;如果文本框模糊,则应隐藏该 div。这似乎有效。现在,我想让 div 保持可见,或者如果我单击 div(或其内容之一)本身,则可以对 div 进行任何单击。这是行不通的。onBlur 事件阻止 div 上的任何事件。我已经尝试确定单击了哪个新元素,但找不到任何对我有帮助的属性。相关目标为 NULL。此时,对我来说唯一的解决方案似乎是在除 div 及其子节点之外的每个其他节点上添加 onfocus
除了这个你还有其他的想法吗?感谢您的帮助。
延斯
javascript ×6
onblur ×6
function ×1
html ×1
jquery ×1
onchange ×1
onfocus ×1
reactjs ×1
selection ×1
validation ×1