Javascript 如何在单击链接后显示隐藏的文本框?
我想在单击某个链接时显示一个隐藏的文本框 以下是我目前的代码: HTML:Javascript 如何在单击链接后显示隐藏的文本框?,javascript,html,css,dom,Javascript,Html,Css,Dom,我想在单击某个链接时显示一个隐藏的文本框 以下是我目前的代码: HTML: 添加存款阈值 存款门槛 JavaScript <script type="text/javascript"> function show() { document.getElementById("dThreshold").display ="block"; } </script> 函数show(){ document.getElementById(“dThreshold”).disp
添加存款阈值
存款门槛
JavaScript
<script type="text/javascript">
function show() {
document.getElementById("dThreshold").display ="block";
}
</script>
函数show(){
document.getElementById(“dThreshold”).display=“block”;
}
我希望你们能帮助我。谢谢。请使用以下代码(即,首先访问样式属性): 以下是示例HTML页面的完整源代码:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
function show() {
//document.getElementById("dThreshold").display ="block";
document.getElementById("dThreshold").style.display = "block";
}
</script>
</head>
<body>
<a href="javascript:void(0);" onclick="show();">Add Deposit Threshold</a>
<div id="dThreshold" style="display: none">
...
</div>
</body>
</html>
函数show(){
//document.getElementById(“dThreshold”).display=“block”;
document.getElementById(“dThreshold”).style.display=“block”;
}
...
改用以下代码(即,首先访问样式属性):
以下是示例HTML页面的完整源代码:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
function show() {
//document.getElementById("dThreshold").display ="block";
document.getElementById("dThreshold").style.display = "block";
}
</script>
</head>
<body>
<a href="javascript:void(0);" onclick="show();">Add Deposit Threshold</a>
<div id="dThreshold" style="display: none">
...
</div>
</body>
</html>
函数show(){
//document.getElementById(“dThreshold”).display=“block”;
document.getElementById(“dThreshold”).style.display=“block”;
}
...
编辑:如果您没有使用Jquery,关于访问样式的其他注释是正确的
以下是一个快速示例,您可以理解并修改该示例以满足您的需要:
javascript:
$('#show').click(function(){
$('input').css('display', 'block');
})
html:
编辑:如果您没有使用Jquery,关于访问样式的其他注释是正确的 以下是一个快速示例,您可以理解并修改该示例以满足您的需要: javascript:
$('#show').click(function(){
$('input').css('display', 'block');
})
html:
试试这个:
注意:在html之前包含脚本。否则,show()将是未定义的
<script>
function show() {
document.getElementById("dThreshold").style.display ="block";
}
</script>
<a onclick="show()">Add Deposit Threshold</a>
<div id="dThreshold" style="display:none">
<table class="table">
<tr>
<td><b>Deposit Threshold</b></td>
<td><div class="row"><div class="col-xs-12"><input type="text" class="form-control" name="Threshold"></div></div></td>
</tr>
</table>
</div>
函数show(){
document.getElementById(“dThreshold”).style.display=“block”;
}
增加存款门槛
存款门槛
试试这个:
注意:在html之前包含脚本。否则,show()将是未定义的
<script>
function show() {
document.getElementById("dThreshold").style.display ="block";
}
</script>
<a onclick="show()">Add Deposit Threshold</a>
<div id="dThreshold" style="display:none">
<table class="table">
<tr>
<td><b>Deposit Threshold</b></td>
<td><div class="row"><div class="col-xs-12"><input type="text" class="form-control" name="Threshold"></div></div></td>
</tr>
</table>
</div>
函数show(){
document.getElementById(“dThreshold”).style.display=“block”;
}
增加存款门槛
存款门槛
这是您的问题:
document.getElementById("dThreshold").style.display ="block";
正确的语法是包含样式
您还需要一个单击的位置:
<form>
<input type="button" onclick="show()" value="click here" />
</form>
这是您的问题:
document.getElementById("dThreshold").style.display ="block";
正确的语法是包含样式
您还需要一个单击的位置:
<form>
<input type="button" onclick="show()" value="click here" />
</form>
我认为你应该改变
document.getElementById("dThreshold").display ="block";
到
我认为你应该改变
document.getElementById("dThreshold").display ="block";
到
虽然您已经有了很多答案,但我认为您应该将JavaScript移到HTML之外,并使用不引人注目的JavaScript,这也可以使函数更普遍地适用。我的第一个建议是使用DOM遍历找到适当的
元素来显示:
// naming the function, the event argument
// is supplied automatically from the
// EventTarget.addEventListener() method:
function show(event) {
// stopping the event bubbling (assuming you
// want to, if not remove the line):
event.stopPropagation();
// finding the next element-sibling of the clicked
// element, and setting the display property of the
// element's style objects to 'block':
this.nextElementSibling.style.display = 'block';
}
// creating an array from all the <a> elements with the class
// of 'toggle':
var toggles = Array.from(document.querySelectorAll('a.toggle'));
// iterating over the Array of elements using
// Array.prototype.forEach():
toggles.forEach(function(toggle) {
// 'toggle' the array-element of the array
// over which we're iterating.
// setting the function show() as the
// event-handler for the 'click' event:
toggle.addEventListener('click', show);
});
a.toggle{
显示:块;
}
存款门槛
其他详情
虽然您已经有了很多答案,但我认为您应该将JavaScript移到HTML之外,并使用不引人注目的JavaScript,这也可以使函数更普遍地适用。我的第一个建议是使用DOM遍历找到适当的
元素来显示:
// naming the function, the event argument
// is supplied automatically from the
// EventTarget.addEventListener() method:
function show(event) {
// stopping the event bubbling (assuming you
// want to, if not remove the line):
event.stopPropagation();
// finding the next element-sibling of the clicked
// element, and setting the display property of the
// element's style objects to 'block':
this.nextElementSibling.style.display = 'block';
}
// creating an array from all the <a> elements with the class
// of 'toggle':
var toggles = Array.from(document.querySelectorAll('a.toggle'));
// iterating over the Array of elements using
// Array.prototype.forEach():
toggles.forEach(function(toggle) {
// 'toggle' the array-element of the array
// over which we're iterating.
// setting the function show() as the
// event-handler for the 'click' event:
toggle.addEventListener('click', show);
});
a.toggle{
显示:块;
}
存款门槛
其他详情
是否尝试了document.getElementById(“dThreshold”).style.display=“block”?是否尝试过document.getElementById(“dThreshold”).style.display=“block”?她没有使用jquery!啊!!好电话。我的坏:)她没有使用jquery!啊!!好电话。我的错:)