我如何获得自定义属性" mem_name"价值?
<input class="messageCheckbox" type="checkbox" value="3" mem_name='ABC' name="checkmember" >
<input class="messageCheckbox" type="checkbox" value="1" mem_name='PQR' name="checkmember" >
<input type="button" onclick="resend_invite">
function resend_invite() {
if ($('input[name="checkmember"]:checked').length > 0) {
if (confirm('Are you sure you want to send invite to selected Member?')) {
var checkboxes = document.getElementsByName('checkmember');
var vals = "";
for (var i = 0, n = checkboxes.length; i < n; i++) {
if (checkboxes[i].checked)
{
vals += checkboxes[i].$(value).attr('mem_id');
vals += ",";
}
}
alert(vals);
return false;
var vals = vals.replace(/,\s*$/, '');
var vals = vals.replace(/,\s*$/, '');
var valsArray = new Array();
valsArray = vals.split(",");
}
} else {
alert('Please select at least one Member');
return false;
}
}
我想输出像ABC,PQR
我使用&#34; vals + = checkboxes [i]。$(value).attr(&#39; mem_id&#39;);&#34;
但它没有用。
答案 0 :(得分:1)
您应该使用$(checkboxes[i])
来获取与其operations
和properties
关联的jquery对象。
$(checkboxes[i]).attr('mem_name')
function resend_invite() {
if ($('input[name="checkmember"]:checked').length > 0) {
if (confirm('Are you sure you want to send invite to selected Member?')) {
var checkboxes = document.getElementsByName('checkmember');
var vals = "";
for (var i = 0, n = checkboxes.length; i < n; i++) {
if (checkboxes[i].checked)
{
vals += $(checkboxes[i]).attr('mem_name');
vals += ",";
}
}
alert(vals);
return false;
var vals = vals.replace(/,\s*$/, '');
var vals = vals.replace(/,\s*$/, '');
var valsArray = new Array();
valsArray = vals.split(",");
}
} else {
alert('Please select at least one Member');
return false;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class="messageCheckbox" type="checkbox" value="3" mem_name='ABC' name="checkmember" >
<input class="messageCheckbox" type="checkbox" value="1" mem_name='PQR' name="checkmember" >
<input type="button" onclick="resend_invite()" value="Resend">
您可以使用javascript
方法使用纯getAttribute
执行此操作。
function resend_invite() {
if ($('input[name="checkmember"]:checked').length > 0) {
if (confirm('Are you sure you want to send invite to selected Member?')) {
var checkboxes = document.getElementsByName('checkmember');
var vals = "";
for (var i = 0, n = checkboxes.length; i < n; i++) {
if (checkboxes[i].checked)
{
vals += checkboxes[i].getAttribute('mem_name');
vals += ",";
}
}
alert(vals);
return false;
var vals = vals.replace(/,\s*$/, '');
var vals = vals.replace(/,\s*$/, '');
var valsArray = new Array();
valsArray = vals.split(",");
}
} else {
alert('Please select at least one Member');
return false;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class="messageCheckbox" type="checkbox" value="3" mem_name='ABC' name="checkmember" >
<input class="messageCheckbox" type="checkbox" value="1" mem_name='PQR' name="checkmember" >
<input type="button" onclick="resend_invite()" value="Resend">
答案 1 :(得分:1)
变化
vals += checkboxes[i].$(value).attr('mem_id');
要
vals += $(checkboxes[i]).attr('mem_id');
答案 2 :(得分:1)
请试试这个小提琴。希望它有效。 Fiddle
$(document).ready(function(){
$("#memAdd").click(function(){
if ($('input[name="checkmember"]:checked').length > 0) {
if (confirm('Are you sure you want to send invite to selected Member?')) {
var checkboxes = document.getElementsByName('checkmember');
var vals = [];
for (var i = 0, n = checkboxes.length; i < n; i++) {
if (checkboxes[i].checked)
{
vals += $(checkboxes[i]).attr('mem_name');
vals += ",";
}
}
alert(vals);
return false;
var vals = vals.replace(/,\s*$/, '');
var vals = vals.replace(/,\s*$/, '');
var valsArray = new Array();
valsArray = vals.split(",");
}
} else {
alert('Please select at least one Member');
return false;
}
});
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class="messageCheckbox" type="checkbox" value="3" mem_name='ABC' name="checkmember" >
<input class="messageCheckbox" type="checkbox" value="1" mem_name='PQR' name="checkmember" >
<input type="button" id="memAdd" value="memAdd">
&#13;