HTML表单元素隐藏的onload javascript
HTML form element hidden onload javascript
尝试在加载时隐藏HTML文本输入,但如果选中单选按钮,则表单将显示
http://pastie.org/private/ah39ul5h4jtmlntkbmmda我已经得到它的工作,我只需要字段隐藏在页面加载。
<form action="profile_edit_gravatar.php" method="post">
<label class="radio inline">
<input type="radio" <?php if($row[16]=='account') {echo ' checked';}?> onload="this.form.otheremail.style.visibility='hidden';" onclick="
if (this.checked) {
this.form.otheremail.style.visibility='hidden';
} else {
this.form.otheremail.style.visibility='visible';
}
return true;
">
Use <?php echo $row[3];?>
</label>
<input type="text" name="otheremail">
</form>
我给无线电和字段一个ID -实际上不太重要,现在我写了一个脚本,使用getElementsByName…
演示<?php $hide = $row[16]=='account'; ?>
<style>
<?php if ($hide) { echo '#otheremail {visibility:hidden;}'; ?>
</style>
<script>
window.onload=function() {
var rads = document.getElementsByName("gravatarradios");
rads[0].onclick=rads[1].onclick=function() {
this.form.otheremail.style.visibility=(this.value=="Use")?'hidden':'visible';
}
if (<?php echo $hide; ?>) rads[0].click(); else rads[1].click();
}
</script>
HTML <form action="profile_edit_gravatar.php" method="post">
<label class="radio" for="gravatarradios1">
<input type="radio" name="gravatarradios" id="gravatarradios1" value="Use">
Use </label>
<label class="radio" for="gravatarradios2">
<input type="radio" name="gravatarradios" id="gravatarradios2" value="Use other">
Use another email:
</label>
<input type="email" name="otheremail" id="otheremail" placeholder="Gravatar email address">
</form>
你可以用CSS样式。默认情况下,这将隐藏所有输入:
input {
visibility: hidden;
}
输入元素没有onload事件,你可以默认使用CSS隐藏元素,然后在单选框被点击时处理它。
另一个选择是对body使用onload。
<body onload="document.forms[0].otheremail.style.visibility='hidden';" >
相关文章:
- JavaScript-动态SVG-onload属性-未触发事件
- 不执行包含的页面的Javascript onload函数
- 使用多个JavaScript Onload函数
- 关于javascript中的window.onload
- body onLoad未调用动态生成的javascript函数
- html onload not running javascript
- iFrame onload JavaScript event
- javascript结合了公共和私有窗口.onload
- 在iframe中禁用onload函数的Javascript
- 为什么 body onload = javascript 函数连续执行
- 使用PhantomJS获取body onload javascript的值
- 窗口加载与 body onload JavaScript 冲突
- 将值从 Servlet 传递到 JSP 中的 onload JavaScript 函数
- window.onload javascript被body.onliad(单选按钮替换)阻止
- window.onload Javascript,带有接收参数的函数
- Onload Javascript不会改变DIV样式
- HTML表单元素隐藏的onload javascript
- OnLoad javascript AJAX Call
- Onload Javascript/jQuery不能在HTML中工作
- if (condition), then body onLoad javascript function