我被要求帮助添加onChange
的选择,所以我想出了这个:jQuery的HTML元素属性名
$("select[name=component]").change(function() {
$("input[name=Code]").val(JSONObject[$(this).selectedIndex].code;
$("input[name=Category]").val(JSONObject[$(this).selectedIndex].category;
$("input[name=UOM]").val(JSONObject[$(this).selectedIndex].uom;
});
提问者告诉我,它没有工作,直到他改变$(this)
到this
这只对我有意义,如果jQuery没有使用我认为是jQuery对象的名称selectedIndex。如果不是,我只需要使用.attr("selectedIndex")
?
jQuery是否将对象从$(this)
(jQuery对象)转换为表单元素或选择对象?
值得指出的是编写'$(this)[0]'是疯狂的。 – nickf 2011-04-21 16:52:26
@nickf好点,补充说。 – 2011-04-21 16:53:31
谢谢@nickf - 我知道这一个;) – mplungjan 2011-04-21 17:03:39