在knockout viewmodel页面中的其他DOM元素上手动触发click事件(Manually trigger click event on other DOM element in knoc

编程入门 行业动态 更新时间:2024-10-25 02:27:55
在knockout viewmodel页面中的其他DOM元素上手动触发click事件(Manually trigger click event on other DOM element in knockout viewmodel page)

在我的HTML中:

<input type="image" src="http://placehold.it/145x145" data-bind="click: imgClick"/> <input type="file" id="artImage" style="display: none;" />

在我的viewmodel中:

var imgClick = function () { $("artImage").click(); };

如果我在'$(“artImage”)上放置调试断点。单击()'行,它就会被击中。 我在控制台中没有错误,但屏幕上没有任何反应。

似乎在小提琴中工作正常? http://jsfiddle.net/nVrSP/所以我不确定为什么它不能在我的页面上工作。

(如果有人问,我正在尝试做一个可点击的图像来触发文件上传浏览)

In my html:

<input type="image" src="http://placehold.it/145x145" data-bind="click: imgClick"/> <input type="file" id="artImage" style="display: none;" />

In my viewmodel:

var imgClick = function () { $("artImage").click(); };

If I put a debug breakpoint on the '$("artImage").click()' line, it is hit. I get no error in the console, nothing happens on screen though.

Seems to work ok in a fiddle? http://jsfiddle.net/nVrSP/ so I'm not sure why it's not working on my page.

(in case anyone asks, I'm trying to do a clickable image to trigger a file upload browse)

最满意答案

你的选择器很可能没有返回任何内容,因为你还没有给它#说“这是ID”。

尝试

$("#artImage").trigger('click');

请参阅此链接以获取有效选择器列表: https : //cdn.tutsplus.com/net/uploads/legacy/154_cheatsheet/jquery12_colorcharge.png

your selector is probally returning nothing as you have not given it a # to say "this is ID."

try

$("#artImage").trigger('click');

see this link for list of valid selectors: https://cdn.tutsplus.com/net/uploads/legacy/154_cheatsheet/jquery12_colorcharge.png

更多推荐

本文发布于:2023-07-28 23:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1310139.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   事件   页面   DOM   viewmodel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!