Jquery,在表中设置 td 的值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23013484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 02:09:43  来源:igfitidea点击:

Jquery, set value of td in a table?

jquery

提问by Ola

I create dynamic a table with <tr>and <td>tags. One of the td tags gets the id "detailInfo". I have an onclick function on some button. I would like to set some value in the td "detailInfo" after pressing on the button.

我创建了一个带有<tr><td>标签的动态表。td 标签之一获得 id“detailInfo”。我在某个按钮上有一个 onclick 功能。按下按钮后,我想在 td“detailInfo”中设置一些值。

So how can I set the value of the td with id "detailInfo" ?

那么如何设置 id 为 "detailInfo" 的 td 的值呢?

This is the td:

这是 td:

<td id="detailInfo" rowspan="2" width="300px">picture detail</td>

回答by Milind Anantwar

use .html()along with selector to get/set HTML:

使用.html()以及选择获取/设置HTML:

 $('#detailInfo').html('changed value');

回答by Alessandro Moreira

From:

从:

it could be:

它可能是:

.html()

.html()

In an HTML document, .html()can be used to get the contents of any element.

在 HTML 文档中,.html()可用于获取任何元素的内容。

.text()

.text()

Unlike the .html()method, .text()can be used in both XML and HTML documents. The result of the .text()method is a string containing the combined text of all matched elements.

与该.html()方法不同,.text()可以在 XML 和 HTML 文档中使用。该.text()方法的结果是一个包含所有匹配元素的组合文本的字符串。

.val()

.val()

The .val()method is primarily used to get the values of form elements such as input, selectand textarea. When called on an empty collection, it returns undefined.

.val()方法主要用于获取input,select和等表单元素的值textarea。当在一个空集合上调用时,它返回undefined.

回答by Pradeep Pansari

You can try below code:

你可以试试下面的代码:

$("Your button id or class").live("click", function(){

    $('#detailInfo').html('set your value as you want');

});

Good Luck...

祝你好运...

回答by Tjaart van der Walt

Try the code below :

试试下面的代码:

$('#detailInfo').html('your value')

$('#detailInfo').html('your value')

回答by Fiambre

$("#button_id").click(function(){ $("#detailInfo").html("WHAT YOU WANT") })