【发布时间】:2012-03-20 12:44:01
【问题描述】:
我对 Javascript 和 jQuery 非常陌生。我正在尝试实现一个下拉选择框,从而在选择某些项目时禁用输入文本框。我能够通过从各种 StackOverFlow 问题中破解一些 jQuery 来实现:
<select name="Severity-of-your-symptoms" id="Severity-of-your-symptoms" class="cformselect" >
<option value="full01_severity_notselected" selected="selected">Please select...</option>
<option value="full01_severity_other">Mild</option>
<option value="full01_severity_other">Moderate</option>
<option value="Severe">Severe</option>
<option value="full01_severity_other">Other</option>
</select>
<br />
<input type="text" id="li-10-14" />
<input type="text" name="firstname" title="First Name" style="color:#888;"
value="First Name" onfocus="inputFocus(this)" onblur="inputBlur(this)" id='color'/>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.4.2.js'></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.js"></script>
<script type="text/javascript">
$('#Severity-of-your-symptoms').change(function() {
$("#li-10-14")[$(this).val() == "full01_severity_other" ? 'show' : 'hide']("fast");
}).change();
$('#Severity-of-your-symptoms').change(function() {
$("#li-10-14")[$(this).val() == "full01_severity_other" ? $('#color').attr("disabled", true)
: $('#color').attr("disabled", false)]
}).change();
</script>
我真的很想用 Javascript 来实现它,但只能用 jQuery 来实现它,谁能帮我把它转换成纯 Javascript 吗?
【问题讨论】:
-
为什么?你有迫切的理由不在 jQuery 中这样做吗?
-
jQuery 是 Javascript。你尝试了什么?你为什么不喜欢 jQuery?
-
感谢 cmets。我知道 jQuery 是一个 Javascript 库,并且它 is Javascript。主要是一个学习练习我想了解如何在没有jQuery库的情况下编写上面的代码。
-
如果你是这样学习javascript的,为什么不从一个更简单的例子开始呢?看起来您正在尝试解决一个实际问题,而没有使用最适合这项工作的工具。
-
更不用说......你如何通过发布 jQuery 来学习,以便其他人为你重新编码
标签: javascript jquery drop-down-menu html-select html-input