jquery 选择器用变量表示
程序员文章站
2024-02-08 10:45:04
...
1、变量id 添加到jquery中
var User = ["Uno", "Uname", "Usex", "Uid", "Ujob", "Udept", "Unow", "Ucphone", "Ucemail", "Uip", "Uphone", "Uhphone", "Uemail"];
$("#"+User[i])
注意:# 后面的整体作为一个变量
2、给:eq()添加变量到选择器中
content[i] = $("#testtable tr:eq(" + j + ") td:nth-child(2)").find("input").val();
变量用+号连接
3、一个简单的例子,实现表格中的数据传到对话框中。
<%-- any content can be specified here e.g.: --%>
<%@ page pageEncoding="UTF-8" %>
<div class="x10">
<div class="line margin-big-bottom bg-white">
<div class="x1"></div>
<div class="x2"><h4 class="text-sub now_address">个人信息</h4></div>
</div>
<div class="line margin-big-top">
<div class="x1"></div>
<div class="x2">
<img src="../img/timg.jpg" width="128" height="128" class="img-border radius-circle" />
</div>
<!--个人信息显示,不可更改-->
<div class="x7 self_info bg-white">
<div class="fr margin-big-right margin-big-top"></div>
<form>
<fieldset>
<legend align="center">
<span class="icon-edit text-sub dialogs" id="editSelfInfo"
data-toggle="click" data-target="#mydialog" data-mask="1" data-width="40%">编辑</span></legend>
<table id="testtable">
<tr>
<td><label>人员编号:</label></td>
<td><input type="text" value="123" /></td>
<td><label>姓名:</label></td>
<td><input type="text" value="小方" /></td>
</tr>
<tr>
<td><label>性别:</label></td>
<td><input type="text" value="女" /></td>
<td><label>身份证号:</label></td>
<td><input type="text" value="1234567890123445" /></td>
</tr>
<tr>
<td><label>职务:</label></td>
<td><input type="text" value="部门员工" /></td>
<td><label>部门:</label></td>
<td><input type="text" value="消防部门" /></td>
</tr>
<tr>
<td><label>岗位:</label></td>
<td><input type="text" value="消防员" /></td>
<td><label>内线电话:</label></td>
<td><input type="text" value="13433452345" /></td>
</tr>
<tr>
<td><label>公司邮箱:</label></td>
<td><input type="text" value="[email protected]" /></td>
<td><label>ip地址:</label></td>
<td><input type="text" value="10.10.10.10" /></td>
</tr>
<tr>
<td><label>个人电话:</label></td>
<td><input type="text" value="13222345340" /></td>
<td><label>住宅电话:</label></td>
<td><input type="text" value="2345634" /></td>
</tr>
<tr>
<td><label>个人邮箱:</label></td>
<td><input type="text" value="[email protected]" /></td>
</tr>
</table>
</fieldset>
</form>
</div>
<div class="x2"> </div>
</div>
<div id="mydialog">
<div class="dialog">
<div class="dialog-head">
<span class="close rotate-hover"></span><strong>修改个人信息</strong>
</div>
<div class="dialog-body">
<table class="modify">
<!-- <tr>
<td>人员编号:</td>
<td><input type="text" /></td>
</tr>-->
<tr>
<td>姓名:</td>
<td><input type="text" placeholder="请输入姓名" name="Uname" id="Uname" /></td>
</tr>
<tr>
<td>性别:</td>
<td>
<input type="radio" name="Usex" id="man" checked="checked" value="男"/>男
<input type="radio" name="Usex" id="woman" value="女">女
</td>
</tr>
<tr>
<td>身份证号:</td>
<td><input type="text" placeholder="请输入身份证号" name="Uid" id="Uid" /></td>
</tr>
<tr>
<td>职务:</td>
<td><input type="text" placeholder="请输入职务" name="Ujob" id="Ujob" /></td>
</tr>
<tr>
<td>部门:</td>
<td> <select name="Udept" id="Udept">
<option>部门经理</option>
<option>员工主管</option>
</select></td>
</tr>
<tr>
<td>岗位:</td>
<td><input type="text" placeholder="请输入岗位" name="Unow" id="Unow"/></td>
</tr>
<tr>
<td>内线电话:</td>
<td><input type="text" placeholder="请输入内线电话" name="Ucphone" id="Ucphone" /></td>
</tr>
<tr>
<td>公司邮箱:</td>
<td><input type="text" placeholder="请输入公司邮箱" name="Ucemail" id="Ucemail" /></td>
</tr>
<tr>
<td>IP地址:</td>
<td><input type="text" placeholder="请输入IP地址" name="Uip" id="Uip" /></td>
</tr>
<tr>
<td>个人电话:</td>
<td><input type="text" placeholder="请输入个人电话" name="Uphone" id="Uphone" /></td>
</tr>
<tr>
<td>住宅电话:</td>
<td><input type="text" placeholder="请输入住宅电话" name="Uhphone" id="Uhphone" /></td>
</tr>
<tr>
<td>个人邮箱:</td>
<td><input type="text" placeholder="请输入个人邮箱" name="Uemail" id="Uemail" /></td>
</tr>
</table>
</div>
<div class="dialog-foot">
<button class="button dialog-close">
取消</button>
<button class="button bg-green" id="submitBtn">
提交</button>
</div>
</div>
</div>
</div>
<style type="text/css">
/*表格式个人信息*/
.self_info table tr td{
padding: 20px 20px;
}
.self_info{
border: 1px solid #f6f6f6;
border-radius:10px;
box-shadow: 0px 3px 3px rgba(225,225,225,0.8);
margin-top: 50px;
}
.self_info table{
margin: 0 auto;
}
.self_info span{
cursor: pointer;
}
.self_info span:active{
color: red;
}
/*表格编辑框 当点击编辑按钮的时候才能编辑*/
.self_info table input{
border: none;
}
.self_info table input[type="text"]{
color: transparent;
text-shadow: 0 0 0 #000;
}
.fr{
float: right;
}
fieldset{
border: 0 none;
border-top: 3px solid #f6f6f6;
margin-top:20px;
}
.modify{
margin: 0 auto;
}
.modify tr td{
padding: 10px 20px;
}
.modify tr td input{
padding-top: 2px;
padding-bottom: 2px;
padding-left: 10px;
padding-right: 10px;
border: 1px solid lightgray;
}
.modify tr td input:hover{
border: 1px solid #0099CC ;
}
</style>
<script type="text/javascript">
$("#editSelfInfo").click(function () {
var User = ["Uno", "Uname", "Usex", "Uid", "Ujob", "Udept", "Unow", "Ucphone", "Ucemail", "Uip", "Uphone", "Uhphone", "Uemail"];
var content = new Array();
var len = User.length;
for (var i = 0; i < len; i++) {
var j = Math.floor(i / 2);
var n = i % 2;
if (n === 0) {
content[i] = $("#testtable tr:eq(" + j + ") td:nth-child(2)").find("input").val();
if (content[i] === "女") {
$("#woman").attr("checked", true);
} else {
$("#man").attr("checked", true);
}
}
if (n !== 0) {
content[i] = $("#testtable tr:eq(" + j + ") td:nth-child(4)").find("input").val();
}
$("#"+User[i]).attr("value",content[i]);
}
});
$("#submitBtn").click(function () {
var Uname = $("#Uname").val();
var Uid = $("#Uid").val();
var Ujob = $("#Ujob").val();
var Udept = $("#Udept").val();
var Unow = $("#Unow").val();
var Ucphone = $("#Ucphone").val();
var Ucemail = $("#Ucemail").val();
var Uip = $("#Uip").val();
var Uphone = $("#Uphone").val();
var Uhphone = $("#Uhphone").val();
var Uemail = $("#Uemail").val();
// var Uid = $("#Uname").val();
$.ajax({
type: 'post',
url: "",
data: {
},
cache: false,
dataType: 'json',
success: function (data) {
//获取返回的数据填充td
},
error: function () {}
});
});
</script>
上一篇: git 中文文件名乱码
下一篇: git 显示中文乱码解决方法