Php 输入类型密码值?
您好,我遇到以下问题: 我有两个输入字段。一个是登录用户名,即,另一个是密码。现在我想设置这两个字段的值。我的问题是密码。我的意愿是实现以下目标: HTML: 问题是,这一直到提交表单时为止。如果出现错误,由于type=text标记,密码将再次可见。所以我如何解决这个问题,如果有人能帮我,我真的很感激。非常感谢 更新:Php 输入类型密码值?,php,javascript,html,forms,input,Php,Javascript,Html,Forms,Input,您好,我遇到以下问题: 我有两个输入字段。一个是登录用户名,即,另一个是密码。现在我想设置这两个字段的值。我的问题是密码。我的意愿是实现以下目标: HTML: 问题是,这一直到提交表单时为止。如果出现错误,由于type=text标记,密码将再次可见。所以我如何解决这个问题,如果有人能帮我,我真的很感激。非常感谢 更新: <div class="small2"> <?php if (!isset($errors['log_password'])):?> <input
<div class="small2">
<?php if (!isset($errors['log_password'])):?>
<input
type="<?= $passwordVal == "" ? "text" : "password" ?>"
id="log_password" name="log_password"
value="<?php echo ($log_password);?>"
placeholder="Passwort"
onfocus="if(this.value=='Passwort')this.value=''"
onblur="if(this.value=='') this.value=this.defaultValue;"/>
<?php endif;?>
<?php if (isset($errors['log_password'])):?>
<input class="log-err"
type="<?= $passwordVal == "" ? "text" : "password" ?>"
id="log_password" name="log_password"
value="<?php echo ($log_password);?>"
placeholder="Passwort"
onfocus="if(this.value=='Passwort')this.value=''"
onblur="if(this.value=='') this.value=this.defaultValue;"/>
<?php endif;?>
</div>
使用
如果必须将其用作文本字段以显示密码,则应将输入类型设置为有条件的:
<?php
// in case of error, the value that the user entered will be passed back via GET (POST?)
$passwordVal = isset($_GET['log_password']) ? $_GET['log_password'] : "";
?>
<!-- if ($passwordVal) is an empty string, type is "text", else type is "password". -->
<input type="<?= $passwordVal == "" ? "text" : "password" ?>" ... />
使用
如果必须将其用作文本字段以显示密码,则应将输入类型设置为有条件的:
<?php
// in case of error, the value that the user entered will be passed back via GET (POST?)
$passwordVal = isset($_GET['log_password']) ? $_GET['log_password'] : "";
?>
<!-- if ($passwordVal) is an empty string, type is "text", else type is "password". -->
<input type="<?= $passwordVal == "" ? "text" : "password" ?>" ... />
我认为,您需要将类型从“text”更改为“password”,如果有错误,您需要将类型从“text”更改为“password”,如果有错误,请编写您认为是函数的代码,然后通过加载页面、焦点事件和模糊事件调用它。
Matt的解决方案很好,但我认为它仅限于支持HTML5的浏览器。编写您认为是函数的代码,然后通过加载页面、聚焦事件和模糊事件调用它。
Matt的解决方案很好,但我认为它仅限于支持HTML5的浏览器。正如Matt正确建议的那样,您可以使用占位符标记 但若要使占位符工作,不能设置值。当然,解决方案是使用条件类型,或者使用jQuery框架。你可以这样做
<?
$your_pass = 'bla-bla-bla';
?>
<!DOCTYPE html>
<html>
<head>
<title>Test page</title>
<!-- Load jQuery library from Google repository -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<form action="#">
<input type="password" name="log_password" id="log_password" />
</form>
</body>
<script>
$(document).ready(function() {
/* execute this by jQuery when document is ready */
/* must use traditional javascript to change input's type attribute */
document.getElementById('log_password').setAttribute('type', 'text');
/* set empty value attribute of input with id "log_password" */
$('input#log_password').attr('val','');
/* set placeholder attribute */
$('input#log_password').attr('placeholder','Password');
$('input#log_password').focus(function(){
/* when input with id log_password is focus.. */
$(this).attr('placeholder','');
/* set the value as you prefer... */
$(this).val('<?=$your_pass?>');
/* reset type of input to password */
document.getElementById('log_password').setAttribute('type', 'password');
});
});
</script>
</html>
正如Matt正确建议的,您可以使用占位符标记 但若要使占位符工作,不能设置值。当然,解决方案是使用条件类型,或者使用jQuery框架。你可以这样做
<?
$your_pass = 'bla-bla-bla';
?>
<!DOCTYPE html>
<html>
<head>
<title>Test page</title>
<!-- Load jQuery library from Google repository -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<form action="#">
<input type="password" name="log_password" id="log_password" />
</form>
</body>
<script>
$(document).ready(function() {
/* execute this by jQuery when document is ready */
/* must use traditional javascript to change input's type attribute */
document.getElementById('log_password').setAttribute('type', 'text');
/* set empty value attribute of input with id "log_password" */
$('input#log_password').attr('val','');
/* set placeholder attribute */
$('input#log_password').attr('placeholder','Password');
$('input#log_password').focus(function(){
/* when input with id log_password is focus.. */
$(this).attr('placeholder','');
/* set the value as you prefer... */
$(this).val('<?=$your_pass?>');
/* reset type of input to password */
document.getElementById('log_password').setAttribute('type', 'password');
});
});
</script>
</html>
文档上的脚本可以检查log\u password值是否为password并更改类型
哦,很抱歉,请看deste的post+1了解这一点文档上的脚本如何准备好检查log\u password值是否为password并更改类型
哦,抱歉,我看不到deste的post+1,那么值的文本类型呢?这应该是可读的。@bonny密码永远不应该是可读的-应该用星号混淆。占位符属性将允许密码对用户可见,直到焦点被赋予该输入,只要它没有赋值。这不起作用。值=密码在加载时不可见page@bonny在这种情况下,您使用的是不支持HTML5的旧浏览器;改用一个新的设计。@Quentin:不是每个人都有能力改变设计。在一个完美的世界里,这是可能的,但有些人没有权力做出这些决定,不得不生活在上级的限制之内。那么价值的文本类型呢?这应该是可读的。@bonny密码永远不应该是可读的-应该用星号混淆。占位符属性将允许密码对用户可见,直到焦点被赋予该输入,只要它没有赋值。这不起作用。值=密码在加载时不可见page@bonny在这种情况下,您使用的是不支持HTML5的旧浏览器;改用一个新的设计。@Quentin:不是每个人都有能力改变设计。在一个完美的世界里,这是可能的,但有些人没有权力做出这些决定,必须生活在上级的限制之内。使用适当的元素。不要滥用value属性。@Quentin我想指出,如果使用占位符属性,这并不总是必要的。但是,建议每个标签都有一个对应的。@Matt-来自规范:占位符属性不应用作标签的替代。占位符属性表示用于帮助用户输入数据的单词或短语的简短提示。提示可以是示例值,也可以是预期格式的简要说明。@Quentin+1表示对我的支持:-使用合适的元素。不要滥用value属性。@Quentin我想指出,如果使用占位符属性,这并不总是必要的。但是,建议每个标签都有一个对应的。@Matt-来自规范:占位符属性不应用作标签的替代。占位符属性表示用于帮助用户输入数据的单词或短语的简短提示。提示可以是示例值,也可以是预期格式的简要说明。@Quentin+1表示对我的支持:-我已经编辑了我的答案,以便非html5浏览器更容易访问。我已经编辑了我的答案,以便非html5浏览器更容易访问。您好,我认为您的解决方案将是处理此问题的最佳方法。我以前从未使用过jquery。威尔
你是那么友好,可以评论每一行吗?我仍然在寻找与javascript的相似之处,但我看不到该函数将在何处调用。。。php变量也是不可理解的。谢谢。我补充一些意见。请记住,这只是一个示例,向您展示如何通过jQuery使用DOM。。。为了满足您的需要,也许您必须将php和jQuery结合起来。您可以在上找到手册和大量示例;相信我:这确实是一个简单的框架。最后一点:正如@Quentin所说:不要滥用占位符标签!在这种情况下,可以更好地使用一个简单的标签,并将输入作为密码字段。您好,我认为您的解决方案将是处理此问题的最佳方式。我以前从未使用过jquery。你会那么友好,可以评论每一行吗?我仍然在寻找与javascript的相似之处,但我看不到该函数将在何处调用。。。php变量也是不可理解的。谢谢。我补充一些意见。请记住,这只是一个示例,向您展示如何通过jQuery使用DOM。。。为了满足您的需要,也许您必须将php和jQuery结合起来。您可以在上找到手册和大量示例;相信我:这确实是一个简单的框架。最后一点:正如@Quentin所说:不要滥用占位符标签!在这种情况下,最好只使用一个标签,并将输入作为密码字段。
<?
$your_pass = 'bla-bla-bla';
?>
<!DOCTYPE html>
<html>
<head>
<title>Test page</title>
<!-- Load jQuery library from Google repository -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<form action="#">
<input type="password" name="log_password" id="log_password" />
</form>
</body>
<script>
$(document).ready(function() {
/* execute this by jQuery when document is ready */
/* must use traditional javascript to change input's type attribute */
document.getElementById('log_password').setAttribute('type', 'text');
/* set empty value attribute of input with id "log_password" */
$('input#log_password').attr('val','');
/* set placeholder attribute */
$('input#log_password').attr('placeholder','Password');
$('input#log_password').focus(function(){
/* when input with id log_password is focus.. */
$(this).attr('placeholder','');
/* set the value as you prefer... */
$(this).val('<?=$your_pass?>');
/* reset type of input to password */
document.getElementById('log_password').setAttribute('type', 'password');
});
});
</script>
</html>