简体   繁体   中英

Java Script in a visual webpart of Sharepoint 2010 site

I am having three buttons to display the images in small,medium and large sizes and this works on a java script and the problem is when i click the say i clicked small button the image is becoming small but the page is being refreshed so that the image is coming back to the normal state..I need to avoid the page refresh on a button clcik...

function changeimg(imgsize) {
    // improve later:  grey-out/disable currently irrelevant button
    var imgwidth, imgheight, imgid;

    switch (imgsize) {
        case small: imgwidth = smaWidth; imgheight = smaHeight; imgid = '1'; break;
        case medium: imgwidth = medWidth; imgheight = medHeight; imgid = '2'; break;
        case large: imgwidth = larWidth; imgheight = larHeight; imgid = '3'; break;
        default: alert('Javascript error 1; please shoot the author');
    }

    for (var n = 0; n < imgArr.length; n++) {
        imgElement = 'img' + imgArr[n][iname];
        document.images[imgElement].width = imgArr[n][imgwidth];
        document.images[imgElement].height = imgArr[n][imgheight];
        document.images[imgElement].src = 'img/' + imgArr[n][iname] + imgid + '.jpg';
    }

}

我假设您正在使用asp按钮,则需要关闭提交行为。

<asp:Button ID="myButton" runat="server" UseSubmitBehavior="False" />
<asp:Button ID="myButton" runat="server" onClientClick="your-JS-code; return false;" />

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