How do I write the click event for code below in jQuery?
how do I write the click event for code below?
var prodName = ["Phlips camera","HP keyboard","iPad","iPhone","Dell Mouse","shirts","books","samsung mobiles","samsung TV", "Phlips TV"," HP Mouse","iPad Charger","iPhone Charger","Dell Keyboard"," T shirts"," Ebooks"];
var cartVal = [];
//add to cart
$('#addcart').live("click",function()
{
alert( prodName[id]+" Item Added");
cartVal[item_count] = id;
//alert("Item Count :::::" + item_count + " Selected Id:::: " + id);
item_count++;
});
//create a list to display the selected product in the cart.
for(var l=0 ;l< cartVal.length; l++)
{
//alert(" name ::::"+ prodName[cartVal[l]]);
var listItem = document.createElement('li');
listItem.setAttribute('id','listitem_'+ l);
listItem.setAttribute('data-icon','false');
listItem.setAttribute('data-theme','c');
listItem.innerHTML = "<a href='#' data-role='button' data-theme ='c' id='" + cartVal[l] + "' rel='external' data-inline='true' style='margin-left:1em;'> <font size='2'>"+ prodName[cartVal[l]] + "</font><span id='viewPage' class='ui-li-count'>View</span></a> <a href='#' id='delete' data-role='button' data-rel='dialog' data-transition='slideup'> Purchase album</a>";
parent.appendChild(listItem);
}
Here I want to write two click event for both anchor tag <a>
.. if I click view or the product name, it display th开发者_运维百科e details , then I click delete icon it deletes product the list..for e.g.: there is 5 items in the shopping list I want to delete two or three products?
U can add the following function in onclick of the anchor tag for id delete
<a href='#' id='delete' **onclick=removeCurrentItem(event)** data-role='button' data-rel='dialog' data-transition='slideup'> Purchase album</a>
function removeCurrentItem(event){
var tar_ele;
if ($.browser.msie) {
// IE takes SRCELEMENT for event source.
// may the force shred IE.
tar_ele = $(e.srcElement);
} else {
tar_ele = $(e.target);
}
// remove the current Li tag
tar_ele.parent().find('li').remove();
}
similiarly for the View span u can have the following code
<a href='#' data-role='button' data-theme ='c' id='" + cartVal[l] + "' rel='external' data-inline='true' style='margin-left:1em;'> <font size='2'>"+ prodName[cartVal[l]] + "</font><span id='viewPage' class='ui-li-count' **onclick=showDetails(event)**>View</span></a>
where the showDetails function will show the details of the product. for ex.
function showDetails (event){
var tar_ele;
if ($.browser.msie) {
// IE takes SRCELEMENT for event source.
// may the force shred IE.
tar_ele = $(e.srcElement);
} else {
tar_ele = $(e.target);
}
// remove the current Li tag
var id = tar_ele.parent('a').attr("id");
// NOW do the requisiste display using the ID.
}
精彩评论