开发者

How to change bg of a table row, selected by its attribute value?

I've an HTML table with where 开发者_运维知识库each row has a unique attribute. I want to change the bg of a row when the user selects its unique id in a form text field.

It has to be js, I don't want the form to post.

Thanks


Although some of your HTML code would be appreciated, here is a basic implementation.

$('form').submit(function() {
    var attributeToSearch = $('.search').val();
    $('table tr[uniqueAttribute="' + attribute + '"]').css('background', 'red');
});

The HTML is supposed to be like this:

<table>
    <tbody>
        <tr uniqueAttribute="foo">...</tr>
        <tr uniqueAttribute="bar">...</tr>
    </tbody>
</table>

And the form:

<form>
    <fieldset>
        <input type="text" class="search" />
        <input type="submit" />
    </fieldset>
</form>

On form submit we check the input the user entered and search for the table row which has that attribute value and change its background.


If I understood you correctly, this should suit you: http://jsfiddle.net/fFApC/

Leave a comment if you need clarification/code update.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜