I am trying to set the value of a js variable when clicking a link.
This is what I have attempted so far (simplified):
<a href="#?id=1" value="1" class="delete_link">Click to delete this row</a>
$(document).ready(function(){
$(".delete_link").click(function(){
var deleteID = $(this).val();
alert(deleteID);
});
}):
But this does not set the variable deleteID
to 1. Am I selected the data in the link incorrectly?
Heres a jsfddle: link
I am trying to set the value of a js variable when clicking a link.
This is what I have attempted so far (simplified):
<a href="#?id=1" value="1" class="delete_link">Click to delete this row</a>
$(document).ready(function(){
$(".delete_link").click(function(){
var deleteID = $(this).val();
alert(deleteID);
});
}):
But this does not set the variable deleteID
to 1. Am I selected the data in the link incorrectly?
Heres a jsfddle: link
Share Improve this question asked Apr 26, 2013 at 15:58 crmephamcrmepham 4,76019 gold badges87 silver badges163 bronze badges 02 Answers
Reset to default 7Try:
var deleteID = $(this).attr("value");
DEMO: http://jsfiddle/CjS8k/3/
value
isn't a valid attribute for <a>
elements, meaning it won't be put into the .value
property (which is what .val()
will return). So instead, use:
<a href="#?id=1" data-value="1" class="delete_link">Click to delete this row</a>
with:
var deleteID = $(this).attr("data-value");
DEMO: http://jsfiddle/CjS8k/4/
there "value" is an attribute.
change your line to
var deleteID = $(this).attr("value");
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745116589a4612163.html
评论列表(0条)