单击 HTML 选择选项时如何使用 jQuery 显示 html?
我有一些 html,希望在单击
jQuery:
$('#addSubject').click(function(){
$('#pgHide').show();
$('span.centerMessage').hide();
$('#addSubjectPopup').show();
});
HTML:
<select>
<option id="addSubject">Add Subject</option>
</select>
<div id="pgHide" style="display: none; ">
<span class="centerMessage">
<img src="../images/loading.gif" />
Creating...</span>
<div class="centerMessage" id="addSubjectPopup" style="display: none;">
<span class="closePopup">close</span>
<div id="insideCenterMessage">
<label>Add Subject</label>
<input type="text" name="subject" id="addSubjectField">
<input type="submit" value="Add Subject" id="addSubjectBttn">
</div>
</div>
I have some html that I want shown when a certain <option>
on a <select>
was clicked. I have the code below for the HTML below that. Is that how it would be done? It doesn't seem to be working even though there are no errors.
jQuery:
$('#addSubject').click(function(){
$('#pgHide').show();
$('span.centerMessage').hide();
$('#addSubjectPopup').show();
});
HTML:
<select>
<option id="addSubject">Add Subject</option>
</select>
<div id="pgHide" style="display: none; ">
<span class="centerMessage">
<img src="../images/loading.gif" />
Creating...</span>
<div class="centerMessage" id="addSubjectPopup" style="display: none;">
<span class="closePopup">close</span>
<div id="insideCenterMessage">
<label>Add Subject</label>
<input type="text" name="subject" id="addSubjectField">
<input type="submit" value="Add Subject" id="addSubjectBttn">
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
元素不会触发点击事件,只有
的选定值:
或者,如果您希望继续通过 HTML 指定目标
, 然后:
<option>
elements don't fire click events, only the<select>
s do. Instead, you can check the selected value of the<select>
after it's been changed:Or if you prefer to continue to specify the target
<option>
through the HTML, then:然后你必须像这样改变你的标记
,使用
You'll have to change your markup like this
then, use