简体   繁体   English

单击特定行上的图像时,在该行上的图像之间切换

[英]Toggle between images on a particular row when clicked on images on that row

Here what i am trying to ask is, i have used the “tabledit” jquery plugin for table specifications.这里我想问的是,我使用了“tabledit”jquery 插件来进行表格规范。 Hence i am adding “images” through “tabledit” “html:” keyword, like below code i am adding "images".因此我通过“tabledit”“html:”关键字添加“图像”,就像下面的代码我添加“图像”。 screen shot of my web page我的网页的屏幕截图

 $('#projectsTable').Tabledit({ url: '#', deleteButton: false, buttons: { edit: { class: 'btn btn-primary secodary', html: '<img src="/concrete5/application/images/animated/btn_edit.png" id="edit" /><img src="/concrete5/application/images/animated/btn_ok.png" id="ok" style="display:none" />', action: 'edit' } }, columns: { identifier: [1, 'Projects'], hideIdentifier: true, editable: [[1, 'Projects'], [2, 'Subprojects'],[8, 'Project Status', '{"1": "Open", "2": "Closed"}']] }, onDraw: function() { console.log('onDraw()'); }, onSuccess: function(data, textStatus, jqXHR) { console.log('onSuccess(data, textStatus, jqXHR)'); console.log(data); console.log(textStatus); console.log(jqXHR); }, onFail: function(jqXHR, textStatus, errorThrown) { console.log('onFail(jqXHR, textStatus, errorThrown)'); console.log(jqXHR); console.log(textStatus); console.log(errorThrown); }, onAlways: function() { console.log('onAlways()'); }, onAjax: function(action, serialize) { console.log('onAjax(action, serialize)'); console.log(action); console.log(serialize); } });

but here i want toggle between “edit” and “ok” images on particular row when i clicked on that row button.但在这里,当我单击该行按钮时,我想在特定行的“编辑”和“确定”图像之间切换。 But as i implemented it only toggle between images in first row of my table, this code is not applicable for remaining rows images.但是当我实现它时,它只在表格第一行的图像之间切换,此代码不适用于剩余的行图像。 So can anyone tell me how can i implement this code to every row of my table.那么谁能告诉我如何将这段代码实现到我表的每一行。 result of my java script function ,the code what i tried is我的java脚本函数的结果,我尝试的代码是

var toggle = true;
function changing() 
{
document.getElementById("edit").style.display = toggle ? 'none' : 'block';
document.getElementById("ok").style.display = toggle ? 'block' : 'none';
toggle = !toggle; 
}

Anyone please suggest me how to toggle between images on particular row images clicked.任何人都请建议我如何在单击的特定行图像上的图像之间切换。

The code is applying it on element with id = edit , which is not what you want.代码将其应用于id = edit元素,这不是您想要的。 The function is applying for the 1st matching element you get back from document.getElementById('edit') , in your case just the first row.该函数正在申请您从document.getElementById('edit')返回的第一个匹配元素,在您的情况下只是第一行。

you can try this way toggle()你可以试试这种方式切换()

//this assumes you have jquery. can also be acheived via vanilla js as well.
//listen to click event on the .edit and .ok (classes) buttons
// also good idea to increase accuracy by img.edit and img.ok instead of just matching on classes
$(function(){
    $('.edit').on('click',function(){   
       $(this).toggle();  
       //show the ok button which is just next to the edit button
       $(this).next(".ok").toggle();  
    });

    $('.ok').on('click',function(){ 
       $(this).toggle();  
       $(this).prev(".edit").toggle();     
    });
})

a even better approach更好的方法

In the table edit action html just update like sotable编辑动作 html 中像这样更新

html: '<img class="edit" />',

css css

.edit {
 background: url("/concrete5/application/images/animated/btn_edit.png") no-repeat scroll 0 0 transparent;
}

.ok {
background: url("/concrete5/application/images/animated/btn_ok.png") no-repeat scroll 0 0 transparent;
}

script脚本

$(function(){
    $('.edit').on('click',function(){   
         $(this).toggleClass( "ok" );          
    });
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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