Jquery 如何使隐藏控件可见?
我有一些动态控件和数据,下面是动态控件的代码:Jquery 如何使隐藏控件可见?,jquery,Jquery,我有一些动态控件和数据,下面是动态控件的代码: <% @user_education.each do |user_edu| %> <script type="text/javascript"> $(document).ready(function() { $("input[value='ADD']").click(function(e) { e.preventDefau
<% @user_education.each do |user_edu| %>
<script type="text/javascript">
$(document).ready(function() {
$("input[value='ADD']").click(function(e)
{
e.preventDefault();
//var field = $("#field").val();
var tb_fromEducation = "<input type='text' style='width:50px' name='ParametersFromSch' value='<%= user_edu.SchoolFrom %>' />";
var tb_ToEducation = "<input type='text' style='width:50px' name='ParametersToSch' value='<%= user_edu.SchoolTo %>' />";
var newRow1 = "<tr><td align='center' style='font-size: large; color: #212121;' >"
+ tb_fromEducation + " to " + tb_ToEducation + "</td></tr>"
+ "<tr><td align='center' style='font-size:large;color:#212121;' >"
newRow1 += "<input type='button' class='btn_rmvsch' value='Remove'/></td></tr>";
var input1 = "<input name='parametersSch' id='field' type='text' value='<%= user_edu.SchoolName %>' />"
var newRow = "<tr><td align='center' style='font-size: x-large; color: #212121;' >" + input1 + "</td></tr>";
$('#ControlsSch').append(newRow);
$('#ControlsSch').append(newRow1);
});
$('#ControlsSch').on('click', '.btn_rmvsch', function() {
var index = $(this).closest('tr').index() + 2
$('#ControlsSch tr:nth-child(n+' + (index - 3) + ')').remove();
return false;
});
});
</script>
<% end %>
$(文档).ready(函数(){
$(“输入[value='ADD']”)。单击(函数(e)
{
e、 预防默认值();
//变量字段=$(“#字段”).val();
var tb_fromEducation=“”;
var tb_ToEducation=“”;
var newRow1=“”
+tb_从教育+”到“+tb_到教育+”
+ ""
newRow1+=“”;
var input1=“”
var newRow=“”+输入1+”;
$('#ControlsSch').append(newRow);
$('#ControlsSch').append(newRow1);
});
$('#ControlsSch')。on('click','.btn#u rmvsch',function(){
var index=$(this).closest('tr').index()+2
$('#ControlsSch tr:n个子项(n++(索引-3)+')).remove();
返回false;
});
});
这些控件是隐藏的,只有html按钮可见,即:
<table>
<tr>
<td align="center">
<table id="SchoolControls" cellpadding="10" cellspacing="10">
</table>
<table id="ControlsSch" cellpadding="10" cellspacing="10">
</table>
<input id="AddSch" type="button" value="ADD" />
</td>
</tr>
</table>
当我点击html按钮“添加”时,它会显示控件。我希望在不点击按钮的情况下,控件应该是可见的。请帮帮我。谢谢 不要使用
单击事件:
$(document).ready(function() {
$("input[value='ADD']").click(function(e)
{
e.preventDefault();
//var field = $("#field").val();
var tb_fromEducation = "<input type='text' style='width:50px' name='ParametersFromSch' value='<%= user_edu.SchoolFrom %>' />";
var tb_ToEducation = "<input type='text' style='width:50px' name='ParametersToSch' value='<%= user_edu.SchoolTo %>' />";
var newRow1 = "<tr><td align='center' style='font-size: large; color: #212121;' >"
+ tb_fromEducation + " to " + tb_ToEducation + "</td></tr>"
+ "<tr><td align='center' style='font-size:large;color:#212121;' >"
newRow1 += "<input type='button' class='btn_rmvsch' value='Remove'/></td></tr>";
var input1 = "<input name='parametersSch' id='field' type='text' value='<%= user_edu.SchoolName %>' />"
var newRow = "<tr><td align='center' style='font-size: x-large; color: #212121;' >" + input1 + "</td></tr>";
$('#ControlsSch').append(newRow);
$('#ControlsSch').append(newRow1);
});
$('#ControlsSch').on('click', '.btn_rmvsch', function() {
var index = $(this).closest('tr').index() + 2
$('#ControlsSch tr:nth-child(n+' + (index - 3) + ')').remove();
return false;
});
//var field = $("#field").val();
var tb_fromEducation = "<input type='text' style='width:50px' name='ParametersFromSch' value='<%= user_edu.SchoolFrom %>' />";
var tb_ToEducation = "<input type='text' style='width:50px' name='ParametersToSch' value='<%= user_edu.SchoolTo %>' />";
var newRow1 = "<tr><td align='center' style='font-size: large; color: #212121;' >"
+ tb_fromEducation + " to " + tb_ToEducation + "</td></tr>"
+ "<tr><td align='center' style='font-size:large;color:#212121;' >"
newRow1 += "<input type='button' class='btn_rmvsch' value='Remove'/></td></tr>";
var input1 = "<input name='parametersSch' id='field' type='text' value='<%= user_edu.SchoolName %>' />"
var newRow = "<tr><td align='center' style='font-size: x-large; color: #212121;' >" + input1 + "</td></tr>";
$('#ControlsSch').append(newRow);
$('#ControlsSch').append(newRow1);
$('#ControlsSch').on('click', '.btn_rmvsch', function() {
var index = $(this).closest('tr').index() + 2
$('#ControlsSch tr:nth-child(n+' + (index - 3) + ')').remove();
return false;
});
});
$(文档).ready(函数(){
$(“输入[value='ADD']”)。单击(函数(e)
{
e、 预防默认值();
//变量字段=$(“#字段”).val();
var tb_fromEducation=“”;
var tb_ToEducation=“”;
var newRow1=“”
+tb_从教育+”到“+tb_到教育+”
+ ""
newRow1+=“”;
var input1=“”
var newRow=“”+输入1+”;
$('#ControlsSch').append(newRow);
$('#ControlsSch').append(newRow1);
});
$('#ControlsSch')。on('click','.btn#u rmvsch',function(){
var index=$(this).closest('tr').index()+2
$('#ControlsSch tr:n个子项(n++(索引-3)+')).remove();
返回false;
});
//变量字段=$(“#字段”).val();
var tb_fromEducation=“”;
var tb_ToEducation=“”;
var newRow1=“”
+tb_从教育+”到“+tb_到教育+”
+ ""
newRow1+=“”;
var input1=“”
var newRow=“”+输入1+”;
$('#ControlsSch').append(newRow);
$('#ControlsSch').append(newRow1);
$('#ControlsSch')。on('click','.btn#u rmvsch',function(){
var index=$(this).closest('tr').index()+2
$('#ControlsSch tr:n个子项(n++(索引-3)+')).remove();
返回false;
});
});
//用Add事件检查新的fiddle
我忘了添加jQuery库,您最好从左侧添加它
更新了FIDDLE,包括JQUERY
要对文档进行大量HTML解析。。。你写了上面的代码吗?不,我写了代码,我是他的代码开发者,我不知道你想完成什么<代码>添加
和删除
这两种方法都有效。。。请参见此处()删除此代码“$”(“输入[value='ADD']”)。单击(函数(e)很好,但html“ADD”不起作用,我想添加更多控件来添加用户信息。你们在这里是靠自己的。我不知道你们想完成什么。我忘了添加jQuery库,你们最好从左侧添加它JSFiddle@Pratik它可以工作,但不会显示控件和数据,它隐藏了控件,只有“添加”按钮是visi我告诉过你们从左面板在JSFIDLE中添加库