doulangbizhan5160 2009-07-28 14:12 采纳率: 100%
浏览 52
已采纳

Javascript - 获取任务图标

I have a small programming problem (php & javascript). On index.php page I'm printing a news (from mysql db) in a table:


CHECKBOX | NEWStitle | NEWStext | NEWSuser | NEWSdate

checkbox1 | News 1 .. | Shall we.. | User0002 | 28.7.09

Above that table I have small icons (images), representing EDIT, DELETE, ARCHIVE, EMAIL and PDF.

I want to achieve following: When user selects one row - with checkbox - (multiple rows won't be supported) and clicks on a icon, I want that javascript finds out which icon was selected, so I can product a custom url (example:index.php?mod=news&command=edit&id=9).

Is there any chance to do that? If, how??


Parrots and Cedric Bertolini, kindly thanks for you answer. jQuery IS valid option, as I have many other effects done with jQuery.

Ok, so far I know how to get checked items along with Id. Now, how to get task icons?

As I have explained, my cms has small icons above the news table, which represents tasks. EDIT, DELETE, ARCHIVE, EMAIL, PDF.

How to write a function for this?

I want to find out which icon was clicked and get newsid (what I already have - thanks to you :)) so I can serve user with desired task.

Thanks again!

  • 写回答

2条回答 默认 最新

  • dor2p0520 2009-07-28 14:22
    关注

    Assumiung the following code for your inputs, where value is the ID:

    <input type="checkbox=" name="newsid" value="9" />Blah blah title, etc
    <input type="checkbox=" name="newsid" value="10" />Blah blah title, etc
    <input type="checkbox=" name="newsid" value="11" />Blah blah title, etc
    

    You can have a javascript function attached to the anchor tag (for example the edit link):

    <a href="#" onclick="editNews()"><img src="edit.png" />Edit</a>
    

    Then use the following javascript function:

    function editNews() {
        val checkedId = $('input[name=newsid]:checked').val();
        window.location = "index.php?mod=news&command=edit&id=" + checkedId;
    }
    

    The key to that function is the $('input[name=newsid]:checked').val() query (which does rely on jQuery), it will find all the input boxes that are named newsid and then find any that are checked.

    If jQuery is not a valid option for your project let us know, otherwise you'll get a ton of recommendations to use it ;)

    If you only want to support one row being selected at a time I suggest using a radio box instead of a checkbox, since that control enforces only one can be selected at a time.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog