我有以下代码:
// Populate the title of the selects on change and trigger a change
$('#modal .update-title')
.change(function () {
var $select = $(this),
match = null,
matchRow = null,
title = $('option:selected', this).prop('title');
在 typescript 中,这将标题的值设置为 bool 值。然后,当我尝试按如下方式使用它时,出现错误:
$("#modal_Title_" + matchRow).val(title);
这是 JQuery 定义的另一个问题还是我做错了什么?当检查定义文件时,我看到以下内容:
prop(propertyName: string): bool;
这似乎与 JQuery 文档不匹配。
最佳答案
jQuery 文档不正确,您的类型定义文件也不正确。
大多数属性是字符串,但有些是数字(例如 .selectedIndex
),有些是 bool 值(.checked
等),还有 $.fn.prop ()
不会将它们全部转换为字符串。
正确的定义应该是:
prop(propertyName: string): any;
已经有一个 work item在 TypeScript 网站上列出来解决这个问题。
关于javascript - .prop 的 JQuery typescript 定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13443502/