我的表单看起来像这样:
[ 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
})
有什么想法吗?
答案 0 :(得分:0)
使用change
事件,如下所示:
$("#ctl00_ContentPlaceHolder_fileUpload").change(function() {
$("#ctl00_ContentPlaceHolder_rbUpload").click(); // sets radio
})