【发布时间】:2010-05-18 14:44:40
【问题描述】:
我想在 JS 函数中使用我传递的参数 (this) 并将其视为 jQuery 变量。 示例:
<script>
function useMe(obj){
$(obj).val();
...
...
...
}
</script>
<select id="selectid" onChange="useMe(this)">
<option>......</option>
</select>
是否有可能将传递的参数视为 jQuery 元素?
顺便说一句。我需要这样做,因为选择元素不是在加载时创建的。稍后将异步创建选择元素。
所以,这行不通:
$("select").each(function (i){
var select_id = $(this).attr("id");
$(this).change(function(e){
因为它还不存在。
感谢您的帮助。
【问题讨论】:
-
您可以使用您的 jQuery 解决方案,您只需要在 select 的 ajax 调用完成后运行脚本。
标签: javascript jquery ajax element arguments