首页 \ 问答 \ 使用javascript / jquery设置TD内容(Setting TD content using javascript/jquery)

使用javascript / jquery设置TD内容(Setting TD content using javascript/jquery)

我试图在javascript函数中替换td标记的内容,但无法弄清楚发生了什么。 这是功能。

function actionCompleted(response, status, data) {

    // Set the id for row
    var rowId = "#rowId-" + response.fieldname;

    // Set the ids for the two table cells we need
    var tdstatusId = "#tdstatusId-" + response.id;
    var tdreasonId = "#tdreasonId-" + response.id;
    alert(tdreasonId);

    try {
        //get the table cell for the status
        var tdstatus = $('#itemDetails').find(rowId).find(tdstatusId);
        //get the table cell for the reason
        var tdreason = $('#itemDetails').find(rowId).find(tdreasonId);

        //Make sure we found our cells
        if (tdstatus != null && tdreason != null) {
            //Set our cell content
            //tdstatus.html(response.ChangeStatus);
            //tdreason.text(response.message); 
            tdstatus.html('TEST');
            tdreason.text('TEST'); 
        }
    }
    catch (e) {
        alert(e.toString());
    }
}

我首先想到jquery找到td控件可能有问题,所以我添加了null检查。

然后我认为它是.text()所以我尝试了.html()。

我想也许是吞下一个例外所以我添加了try..catch。

然后我认为这可能是函数收到的响应对象的问题,所以我在那里扔了一些警报,它们有我需要的值。

我检查了ID并确保它们匹配页面html中找到的id。

我已经检查了我能想到的一切。 但我的代码根本不起作用。 我试图设置的两个TD元素中的第一个包含两个链接(一个标签),但第二个是空的。 所以我认为这与它无关。 我在这里试图解决这个问题。

有什么我做错了吗? 可能还有其他会导致这种行为的事情吗?

提前致谢。


I'm trying to replace the contents of a td tag in a javascript function but can't figure out what's going on. Here is the function.

function actionCompleted(response, status, data) {

    // Set the id for row
    var rowId = "#rowId-" + response.fieldname;

    // Set the ids for the two table cells we need
    var tdstatusId = "#tdstatusId-" + response.id;
    var tdreasonId = "#tdreasonId-" + response.id;
    alert(tdreasonId);

    try {
        //get the table cell for the status
        var tdstatus = $('#itemDetails').find(rowId).find(tdstatusId);
        //get the table cell for the reason
        var tdreason = $('#itemDetails').find(rowId).find(tdreasonId);

        //Make sure we found our cells
        if (tdstatus != null && tdreason != null) {
            //Set our cell content
            //tdstatus.html(response.ChangeStatus);
            //tdreason.text(response.message); 
            tdstatus.html('TEST');
            tdreason.text('TEST'); 
        }
    }
    catch (e) {
        alert(e.toString());
    }
}

I first thought there might be a problem with jquery finding the td controls, so I added the null check.

Then I thought it was the .text() so I tried .html().

I thought maybe it was swallowing an exception so I added the try..catch.

Then I thought it might be an issue with the response object the function received, so I threw some alerts in there and they have the values I need.

I checked the Ids and made sure they matched the id's found in the html of the page.

I've checked everything I could think of. But my code simply doesn't work. The first one of the two TD elements I'm trying to set contains two links (a tags), but the second one is empty. So I don't think that has anything to do with it. I'm at wits end here trying to figure this out.

Is there something I'm doing wrong? Could there be something else that would cause this behavior?

Thanks in advance.


原文:https://stackoverflow.com/questions/6931921
更新时间:2022-02-21 21:02

最满意答案

出现问题的原因是您使用相对路径访问"szs.db"

这是我对python中相对/绝对路径的标准答案: Python ConfigParser无法正确搜索.ini文件(Ubuntu 14,Python 3.4)

这应该可以解决你的问题。


your problem occurs because you access "szs.db" using a relative path.

this is my standard answer to relative/absolute paths in python: Python ConfigParser cannot search .ini file correctly (Ubuntu 14, Python 3.4) .

that should solve your problem.

相关问答

更多
  • 您将需要添加对Microsoft.SqlServer.Management.IntegrationServices的引用。 对我而言,它不会显示在SQL Server文件夹中,我只能在GAC中找到它。 C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Management.IntegrationServices\11.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Management.IntegrationServic ...
  • 你在错误的目录中。 确保你在正确的文件夹,然后运行npm install webpack 。 在你的终端中使用pwd打印当前工作目录,然后ls列出其中的所有文件。 如果没有package.json你不能安装任何东西。 You are in the wrong directory. Make sure you are in the right folder and then run npm install webpack. In your terminal use pwd to print the curre ...
  • 首先感谢回购。 问题是您指定的路径。 当你使用await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder); ,这意味着您将所选数据复制到本地文件夹(不在数据库文件夹中),以将其复制到首先创建数据库文件夹所需的数据库文件夹中,然后将该文件复制到该文件夹中。 现在我给出了一个简单的解决方案,即对AppDBPath进行更改以修复错误。 此解决方案仅将数据库复制到本地文件夹,而不是复制到Database文件夹中 public const str ...
  • 类型是正确的。 在你的脑海中,你可以将PVOID类型改为别的,它应该更有意义, (SIZE_T volatile *, SIZE_T, SIZE_T)等等 The types are correct. In your head you can change the PVOID type to something else and it should make more sense, (SIZE_T volatile *, SIZE_T, SIZE_T) etc.
  • 您正在参考ROS Fuerte的教程,但您似乎使用ROS Kinetic。 Fuerte于2012年发布,Kinetic在2016年发布。两者之间有很大的不同。一个是rosbuild不再是选择的构建系统。 我建议你忘记所有关于rosbuild (由rosbuild代替)和rosws (由wstool代替),并从http://wiki.ros.org/ROS/Tutorials开始新鲜出炉,特别是http://wiki.ros.org/ROS/教程/安装和配置catkin (第3章),并选择catkin 。 ...
  • 为什么会发生这种情况 考虑: dest= [ -d $dest ] 这是做什么的? 它运行命令: [ -d ] 那是做什么的? 它的简写: [ -n "-d" ] ...也就是说,它检查-d是否为空,而不是,所以结果为真。 如何阻止它 使用更多报价 请考虑一下: dest="" [ -d "$dest" ] 运行时,它不会调用[ -d ] ; 相反,它运行[ -d '' ] : 引号阻止扩展结果被分割成不同于它们开始的字符串数 。 在On Bash上,考虑扩展测试表 [[ -d $dest ]] ...
  • 是的,这可以采取相对路径。 为什么你的表达不起作用? 非常简单:您的路径/com/test/Test.xml是绝对的,因为它以/开头,所以您实际上正在从根开始查找位于/com/test/目录中的文件。 如何解决问题? 我相信你正在试图找到你的项目下的文件。 因此,您可以使用相对路径,如./com/test/Test.xml或com/test/Test.xml 。 这可能会有所帮助。 可能是因为我不知道您当前的工作目录和文件结构是什么。 运行java时,您的当前目录是您所在的位置。 如果从IDE运行,通常工作 ...
  • 出现问题的原因是您使用相对路径访问"szs.db" 。 这是我对python中相对/绝对路径的标准答案: Python ConfigParser无法正确搜索.ini文件(Ubuntu 14,Python 3.4) 。 这应该可以解决你的问题。 your problem occurs because you access "szs.db" using a relative path. this is my standard answer to relative/absolute paths in python ...
  • 我希望你在Manifest文件中给予了权限。 另外,我不确定getExternalStoragePublicDirectory(...)是否为您提供了正确的路径。 只需调试并检查您是否正在获取路径 /data/data/com.example.program/databases/xxx.db or not ! Unbelievable, but ...
  • 关于QSqlQuery 您没有正确使用QSqlQuery。 构造函数QSqlQuery(const QString &query = QString(), QSqlDatabase db = QSqlDatabase())执行给定的query 。 引用文档: 使用SQL查询和数据库db构造QSqlQuery对象。 如果未指定db或无效,则使用应用程序的缺省数据库。 如果查询不是空字符串,则将执行该字符串。 而bool QSqlQuery::exec()用于准备查询。 仍然引用文档: 执行以前准备的SQL查询 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)