I have a question concerning the following :

我有一个关于以下问题:

I have a div with display:none. This div appears once a user types text into an input field (with the jQuery show() method). Everything works fine, but once I delete the text typed into the input field, I would like the DIV to disappear again. My attempt:

我有一个带显示的div:none。一旦用户在输入字段中键入文本(使用jQuery show()方法),就会出现此div。一切正常,但一旦我删除输入字段中输入的文本,我希望DIV再次消失。我的尝试:

use another function with the jQuery hide() function if the input is empty, but it prevents the function using show() to be triggered (since the input is obviously empty by default).

如果输入为空,则使用jQuery hide()函数使用另一个函数,但它会阻止使用show()的函数被触发(因为默认情况下输入显然是空的)。

Any ideas would be much appreciated !

任何想法将不胜感激!

Here is my script:

这是我的脚本:

function password1Security()

{
var pwd1 = document.getElementById("password1");
var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
var pwdsft = document.getElementById("passwordSafetyLevel1");

{
if (strongRegex.test(pwd1.value)){pwdsft.innerHTML = '<span style="color:green;">Safe</span>'} else if (mediumRegex.test(pwd1.value)) 

{pwdsft.innerHTML = '<span style="color:orange;">Quite Safe</span>'} else {pwdsft.innerHTML = '<span style="color:red;">Unsafe</span>'};
}
};

function passSafetyAppear1()

{$("#passwordSafety1").show()};

function showPassSafety1()

{
password1Security();
passSafetyAppear1();
};

</script>

<input name="password1" id="password1" type="password" size="15" maxlength="20" style="width:500px; height:30px;" 

onKeyUp="showPassSafety1()"/>
<br/>

<span name="passwordSafety1" id="passwordSafety1" style="font-size:12pt; display:none;">Your password is <b 

name="passwordSafetyLevel1" id="passwordSafetyLevel1"></b>.</span><br/>

Thank you in advance,

先谢谢你,

Pierre

皮埃尔

3 个解决方案

#1


1

Do that operation on blur (when the input loses focus). Use code like this with the proper selectors to achieve this:

在模糊时执行该操作(当输入失去焦点时)。使用这样的代码和适当的选择器来实现这个目的:

$('input-selector').blur(function(){
    if(!$(this).val())
        $('div-selector').hide();
});

更多相关文章

  1. 运行一次后停止执行函数
  2. Javascript日期/时间函数是否依赖于客户端机器?
  3. 是否可以从节点js中的同一模块导出构造函数和一些正常函数?
  4. 在Javascript中将下拉字段乘以文本字段
  5. javaES6箭头函数的全新特性
  6. JavaScript学习-5——异步同步、回调函数
  7. 什么“返回此”在javascript函数中做什么?
  8. jQuery和AJAX - 使用Ajax添加的对象动态不适用于jQuery函数?
  9. Javascript偏函数与柯里化

随机推荐

  1. 基于php生成xml的实例解析
  2. php实现联想搜索,你会吗?
  3. 详解PhpStorm一次性折叠所有函数或者方法
  4. php中carbon如何转成时间戳
  5. PHP中常用header头汇总
  6. PHP让人不知道的匿名函数的几种写法(附代
  7. 如何在php中实现construct构造方法
  8. PHP中三种设置脚本最大执行时间的方法
  9. 在PHP中通过GD库创建简单的图片(图文详解)
  10. 如何将curl获取到的json对象转成数组