简体   繁体   中英

How can I combine that javascript and jQuery function to hide a button?

I downloaded the File upload script called Simple Photo Manager. Since I'm more familiar with jQuery functions I want to use them in combination with the already existing JS code from that script.

I basically want to hide the Delete button when it's clicked. Why is the Delete button not being hidden after I click on it? (Note: the JS files are correctly included into the HTML file) Also, the delLink.removeChild and delLink.appendChild are useless here because it was originally intended for a Delete/Restore switch link, but I decided to go for a button instead.

Thanks a lot if you can help me.

The html code is:

<input type='button' id='deleteit' onClick="deleteLinkOnClick
(this, 'delFlag<?=$imgid?>')">

The JS code for creating that element when an image is uploaded is:

var image_del_link = par.createElement('input');
image_del_link.type = "button";
image_del_link.value = "Delete";
imgdiv.appendChild(image_del_link);

The function for the onclick is: (I tried to write the jQuery function at the bottom)

function deleteLinkOnClick(delLink, delFlag) {
    var par = window.document;
    var imgDiv = delLink.parentNode;
    var image_hidden = delFlag == '' ? imgDiv.childNodes[2] : par.getElementById(delFlag);

    if (image_hidden.value == '1') {

        image_hidden.value = '0';
        delLink.removeChild(delLink.childNodes[0]);
        delLink.appendChild(par.createTextNode("Restore"));
        delLink.style.color = '#FF0000';
    }
    else {
        image_hidden.value = '1';
        delLink.removeChild(delLink.childNodes[0]);
        delLink.appendChild(par.createTextNode("Delete"));
        delLink.style.color = '#64B004';
    }

    $(document).ready(function(){
        $(image_del_link).click(function(){
            $(this).hide();
            });
        });
}

Here it is.

$("#deleteit").click(function(){
    $(this).hide();
})

Try :

$("#deleteit").live("click", function(){
    $(this).hide();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM