当用户点击“input type=”file”时设置单选按钮
我的表单看起来像这样:
[ radio ] Use your current picture
[ radio ] Use the sites default
SELECT THIS ONE DYNAMICALLY --> [ radio ] Upload a picture from your computer
---------------- [BrowseButton]
唯一的问题是,当用户单击输入字段本身(“----”)或浏览按钮时,相应的单选按钮不会变为选择(这是预期的) )。我正在尝试将 Javascript 事件附加到该字段,但似乎没有任何效果。
不确定这是否真的重要,但后端是 .NET,这是用于生成字段的代码:
<li>
<asp:RadioButton ID="rbUpload" GroupName="avatar" runat="server" Text="Upload a new picture from your computer" />
<asp:FileUpload ID="fileUpload" runat="server" /> Maximum file size: 4 MB.
<asp:PlaceHolder ID="FileUploadMessages" runat="server">
</li>
输出以下 HTML:
<li>
<input type="radio" value="rbUpload" name="ctl00$ContentPlaceHolder$avatar" id="ctl00_ContentPlaceHolder_rbUpload"><label for="ctl00_ContentPlaceHolder_rbUpload">Upload a new picture from your computer</label>
<input type="file" id="ctl00_ContentPlaceHolder_fileUpload" name="ctl00$ContentPlaceHolder$fileUpload"> Maximum file size: 4 MB.
</li>
我知道这些类型的字段是“只读”的,但是这里不应该是一个问题......对吗?我尝试附加 jQuery 事件,例如 .click
,但它们似乎不起作用。请参阅这里:
$("#ctl00_ContentPlaceHolder_fileUpload").click(function() {
$("#ctl00_ContentPlaceHolder_rbUpload").click(); // sets radio
})
有什么想法吗?
My form look something like this:
[ radio ] Use your current picture
[ radio ] Use the sites default
SELECT THIS ONE DYNAMICALLY --> [ radio ] Upload a picture from your computer
---------------- [BrowseButton]
The only problem with this is that when a user clicks on either the input field itself ("----"), or the Browse button, the corresponding radio button does not become select (which is expected). I'm trying to attach Javascript events to the field, but nothing seems to be working.
Not sure if it really matters, but the backend is .NET and this is the code that's being used to generate the field:
<li>
<asp:RadioButton ID="rbUpload" GroupName="avatar" runat="server" Text="Upload a new picture from your computer" />
<asp:FileUpload ID="fileUpload" runat="server" /> Maximum file size: 4 MB.
<asp:PlaceHolder ID="FileUploadMessages" runat="server">
</li>
Which spits out the following HTML:
<li>
<input type="radio" value="rbUpload" name="ctl00$ContentPlaceHolder$avatar" id="ctl00_ContentPlaceHolder_rbUpload"><label for="ctl00_ContentPlaceHolder_rbUpload">Upload a new picture from your computer</label>
<input type="file" id="ctl00_ContentPlaceHolder_fileUpload" name="ctl00$ContentPlaceHolder$fileUpload"> Maximum file size: 4 MB.
</li>
I'm aware that these types of fields are "read only", but that shouldn't be an issue here...right? I've tried attaching jQuery events such as .click
, but they don't seem to work. See here:
$("#ctl00_ContentPlaceHolder_fileUpload").click(function() {
$("#ctl00_ContentPlaceHolder_rbUpload").click(); // sets radio
})
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
change
事件,如下所示:Use the
change
event, like this: