在我的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
更多推荐
发布评论